8.8. Capturing HTTP headers

  1. Header captures are useful to track unique request identifiers set by an upper
  2. proxy, virtual host names, user-agents, POST content-length, referrers, etc. In
  3. the response, one can search for information about the response length, how the
  4. server asked the cache to behave, or an object location during a redirection.
  5.  
  6. Header captures are performed using the "capture request header" and "capture
  7. response header" statements in the frontend. Please consult their definition in
  8. section 4.2 for more details.
  9.  
  10. It is possible to include both request headers and response headers at the same
  11. time. Non-existent headers are logged as empty strings, and if one header
  12. appears more than once, only its last occurrence will be logged. Request headers
  13. are grouped within braces '{' and '}' in the same order as they were declared,
  14. and delimited with a vertical bar '|' without any space. Response headers
  15. follow the same representation, but are displayed after a space following the
  16. request headers block. These blocks are displayed just before the HTTP request
  17. in the logs.
  18.  
  19. As a special case, it is possible to specify an HTTP header capture in a TCP
  20. frontend. The purpose is to enable logging of headers which will be parsed in
  21. an HTTP backend if the request is then switched to this HTTP backend.

Example :

  1. # This instance chains to the outgoing proxy
  2. listen proxy-out
  3. mode http
  4. option httplog
  5. option logasap
  6. log global
  7. server cache1 192.168.1.1:3128
  8. # log the name of the virtual server
  9. capture request header Host len 20
  10. # log the amount of data uploaded during a POST
  11. capture request header Content-Length len 10
  12. # log the beginning of the referrer
  13. capture request header Referer len 20
  14. # server name (useful for outgoing proxies only)
  15. capture response header Server len 20
  16. # logging the content-length is useful with "option logasap"
  17. capture response header Content-Length len 10
  18. # log the expected cache behavior on the response
  19. capture response header Cache-Control len 8
  20. # the Via header will report the next proxy's name
  21. capture response header Via len 20
  22. # log the URL location during a redirection
  23. capture response header Location len 20
  24. >>> Aug 9 20:26:09 localhost \
  25. haproxy[2022]: 127.0.0.1:34014 [09/Aug/2004:20:26:09] proxy-out \
  26. proxy-out/cache1 0/0/0/162/+162 200 +350 - - ---- 0/0/0/0/0 0/0 \
  27. {fr.adserver.yahoo.co||http://fr.f416.mail.} {|864|private||} \
  28. "GET http://fr.adserver.yahoo.com/"
  29. >>> Aug 9 20:30:46 localhost \
  30. haproxy[2022]: 127.0.0.1:34020 [09/Aug/2004:20:30:46] proxy-out \
  31. proxy-out/cache1 0/0/0/182/+182 200 +279 - - ---- 0/0/0/0/0 0/0 \
  32. {w.ods.org||} {Formilux/0.1.8|3495|||} \
  33. "GET http://trafic.1wt.eu/ HTTP/1.1"
  34. >>> Aug 9 20:30:46 localhost \
  35. haproxy[2022]: 127.0.0.1:34028 [09/Aug/2004:20:30:46] proxy-out \
  36. proxy-out/cache1 0/0/2/126/+128 301 +223 - - ---- 0/0/0/0/0 0/0 \
  37. {www.sytadin.equipement.gouv.fr||http://trafic.1wt.eu/} \
  38. {Apache|230|||http://www.sytadin.} \
  39. "GET http://www.sytadin.equipement.gouv.fr/ HTTP/1.1"