Stick table - store strings to lookup strings

Hello,
I’m trying to achieve a certain functionality in HAProxy. It might be possible, it might not.

Our customers can use their own (whitelisted) domains.

What I want to achieve
When our main url becomes unresponsive or inaccessible we have a backup url which our customers can use(only) if the main url is down. When the main url is back up, you will get automatically redirected to the main url.

I’d like that redirect, to redirect them back to their original url. That information is unfortunately not currently available. But what we do have is the path they are using and the first part of the path is decisive for where I want to send them.

/env1 https://customurl
/env2 https://anothercustomurl

What I suspect might work

I figure I could do this by storing this data in a sticktable with no expiry. I figured using the path as the key and then store the url. But I could not find a way to do this.

If this is not possible, perhaps I can do something similar with a dynamic map. We only have a few thousand environments so performance wise it might still work.

Hoping someone can give me an insight as to how I can achieve this.

using stick tables you can store strings or arbitrary data by setting the table type to either “string” or “bin” on the table definition line.

It is documented there:

https://docs.haproxy.org/dev/configuration.html#11.1

Example:

# store URLs of max 256 chars, up to 1k entries, no expiry
stick-table type string len 256 size 1k

Since there is no way to remove an entry from a stick-table (aside from expiring), I suggest to use a general purpose counter (gpc) that is either set to 1 to indicate the URL is not accessible, or 0 to indicate the opposite (as if the entry was missing)