New in version 1.5 is the http-response add-header
directive. As written in the documentation — this can be used in frontend
, backend
and listen
.
What I was trying to within a frontend
section:
use_backend some_backend if some_condition
http-response add-header Vary Origin if some_condition
But this has no effect. The same line placed in the backend
section works perfectly fine.
Can someone please help me understand, what I am missing here? I don't understand, why this does not work in the frontend
section.
My guess would be that within the fronted
there is no response yet and so the directive fails. I tried using it before and after die use_backend
directive.
Best Answer
Running haproxy in foreground (
haproxy -d -V -f haproxy.cfg
) with your sample displayed the following warning:Fiddling with my config, I found that this warning is displayed when using this ACL:
But not when using this ACL:
The difference being
res
vs.req
, so checking response headers instead of request headers. This leads me to believe that ahttp-response header
rule in afrontend
is incapable of inspectingrequest
headers.I don't know if this is intended functionality by HAProxy, but it certainly hasn't been clearly documented.