Reputation: 2678
I'm looking to get HAProxy to both set a custom header and log it.
Below is a paired down example of my haproxy.cfg (I've left out some SSL details and multiple backends that I believe are not relevant to my problem)
global
log 127.0.0.1 local0 debug
defaults
log global
stats enable
option httplog
frontend httpFrontendi
mode http
bind *:80
http-request add-header Foo Bar
capture request header Foo len 64
log-format Foo\ %[capture.req.hdr(0)]\ %hr\ %hrl\ %hs\ %hsl
default_backend backend_api
redirect scheme https code 301 if !{ ssl_fc }
backend backend_api
mode http
balance roundrobin
option httpchk HEAD /api/test_db HTTP/1.0
server backend_api1 ip:80 check inter 5s rise 2 fall 3
I call the proxy with:
curl 127.0.0.1
I was then expecting to see the custom header in the log, but it does not show:
Nov 10 17:49:36 localhost haproxy[22355]: Foo - {} -
The hardcoded "Foo" appears, so the log-format
command is clearly working. But everything else renders as empty... are custom headers set after logging? How can one log a custom header?
I am new to HAProxy so I think this may be some understanding I'm missing.
(I start HAProxy with cmd sudo haproxy -f /etc/haproxy/haproxy.cfg
and observe log with sudo tail -f /var/log/haproxy/haproxy.log
. This is on HA-Proxy version 1.6.2)
Upvotes: 5
Views: 12681
Reputation: 1791
You can use this:
http-request add-header Foo Bar
#capture request header Foo len 64
http-request capture req.hdr(Foo) len 64
log-format Foo\ %[capture.req.hdr(0)]\ %hr\ %hrl\ %hs\ %hsl
Note that capture
get executed before http-request
, so you cannot log Foo.
Upvotes: 9