HAProxy log current/modified values


I’ve set it up to capture the request header like so:

capture request header x-custom len 10

Later on I set the header value like so:

http-request set-header X-custom 1 if acl_check

The backend reflects the correct header value but the HAProxy log shows what was passed in with the request not the value I changed it to.

What’s the correct way to log the most up to date information, updates to headers that have been done in during processing ?


Hi Exocomp

Can you please confirm the version of HAProxy that you are using?



Apologies for the delay, I’m on the latest version, 1.8.7.



The reason why you are not able to capture latest value in haproxy.log is that the capture keyword is getting executed before the http-request keyword with set-header argument. This is causing HAProxy to log older value but send the updated value to the backend server.

For HAProxy version above 1.6.x , the http-request keyword is also provided with the capture argument to capture the latest value.

Therefore, you may use following line:
http-request capture hdr(X-Custom) len 10
Instead of:
capture request header X-Custom len 10

Also, you need to ensure that http-request line with set-header argument is positioned before the http-request line with capture argument. This is so because, the http-request keywords are executed in the order that they are declared in the configuration file. And by doing so, you would capture the newly set header value in haproxy.log file.

Your configuration would look like:

frontend fe

bind *:80
http-request set-header X-Custom 1
http-request capture hdr(X-Custom) len 10
default_backend be

Hope this is helpful !



Thanks, that worked!