Migrating rspirep to http-response replace-header

Currently I am using the following haproxy version:
HA-Proxy version 1.8.19-1+deb10u3 2020/08/01

The following backend configuration snippet

backend radicale-https
     ...
     acl hdr_location res.hdr(Location) -m found
     rspirep ^Location:\ (http|https)://127.0.0.1\/(.*) Location:\ /radicale/ if hdr_location
     ...

I would like to upgrade to haproxy 2.2.3 with the following modification:

     acl hdr_location res.hdr(Location) -m found
     http-response replace-header ^Location:\ (http|https)://127.0.0.1\/(.*) Location:\ /radicale/ if { hdr_location }

However when checking the configuration with haproxy, I get the following error message:

     [ALERT] 355/171925 (3198) : parsing [/etc/haproxy/haproxy.cfg:112]: 'http-response replace-header' expects either 'if' or 'unless' followed by a condition but found '{'.

Could someone support me on ho to migrate this configuration line correctly? Thank’s in advance!

Just like in 1.8 with rspirep, the if statements needs to be:

if hdr_location

and not:

if { hdr_location }

Also please read the documentation about http-request replace-header, it’s not a 1:1 replacement for rspirep, the syntax is different:

https://cbonte.github.io/haproxy-dconv/2.4/configuration.html#http-request%20replace-header

OK, I’ve removed the {} signes around hdr_location and checked the configuration again:
[ALERT] 356/000752 (3122) : parsing [/etc/haproxy/haproxy.cfg:112]: ‘http-response replace-header’ expects either ‘if’ or ‘unless’ followed by a condition but found ‘hdr_location’
Something is still not OK. Any other idea?

I say again: the syntax between the two keyword is different, that is why you need to take a look at the documentation that I linked to above, so you know what to do.

Finally I have found the solution at: url rewriting - haproxy rewrite to completely replace host name and redirect base url by default to login - Stack Overflow

Applied to my case, the modified configuration snippet which is passing through the config check (and haproxy service starts with, of course):

acl hdr_location res.hdr(Location) -m found
http-response replace-value Location (http|https)://127.0.0.1\/(.*) /radicale/ if hdr_location

So I successfully migrated from haproxy 1.8.19 to 2.2.9 ! :slight_smile: