Based on this answer, I can successfully override the backend with a query parameter:
backend servers
balance roundrobin
cookie SERVERID insert indirect nocache
use-server web1 if { urlp(SERVERID) -i web1 }
use-server web2 if { urlp(SERVERID) -i web2 }
server web1 web1-internal:80 check cookie web1
server web2 web2-internal:80 check cookie web2
However, I would like for this to "persist" in subsequent requests; i.e. I want a new Set-Cookie with the value from the query parameter to overwrite any existing SERVERID cookies. HAProxy doesn't add a Set-Cookie if the request came in with a valid SERVERID Cookie. Removing the indirect
option didn't work.
Is the only solution to use preserve
and have the backend always respond with Set-Cookie, or is there a way to do this in HAProxy?
Best Answer
I did this by creating new backends that set the SERVERID cookie and routing to them via frontend directives.
We use this for staged rollouts, setting the weight in the
servers
backend to 0, and then testing using the query paramcurrent_site=true
.