12

I'm trying to track down some problems with the way a javascript client is interacting with an application server and would like to see the entire http payload (headers, body, and everything) that is being passed back and forth.

It so happens that there is already an haproxy server in front of the application server, so I was hoping to be able to use haproxy to provide the relevant logs. Obviously this would be bad to turn on in production, but I have a clone of the entire environment that can be isolated while I do this debugging.

Is there a way to get haproxy to log the entire http payload for POST requests going to a particular backend server?

3

Haproxy does not have a facility to log POST content or HTTP bodies.

Use Wireshark instead.

  • Thanks. I ended up being able to see the POST in chrome's developer tools. – Peter Groves Jul 19 '13 at 18:34
  • This is no longer the case. See hack_on's post below. – PMV May 4 '18 at 16:35
23

Apparently since version 1.6.0 (October 2015) you can now. There is a new directive:

option http-buffer-request

That you include in the front-end or back-end to give HAProxy access to the body. And you use req.body to access it. Here is a summary of the config I used:

global
        log     127.0.0.1 local0
        debug
        maxconn 2048
        ulimit-n 8012
#        ...

defaults
    mode http
    option httplog
    log-format frontend:%f/%H/%fi:%fp\ GMT:%T\  body:%[capture.req.hdr(0)]\ request:%r
    option dontlognull
#   ...

frontend www-http
   log global
   option http-buffer-request
# id=0 to store body for logging
   declare capture request len 40000
   bind 7.7.7.7:8007 
   http-request capture req.body id 0

   default_backend www-backend

backend www-backend
    mode http
    option forwardfor
#   ...
  • Hi, is there a way to log this req.body to a different file and not the same default haproxy.log? – Shoaib Khan Jan 30 '19 at 18:55
  • Hi. How to log a request and response body in one log file? – Yuriy Tigiev Feb 10 '20 at 9:40
1

This might help, make sure to keep the lines in the same order. I tested it inside frontend and listen blocks, idk how this will work in backend:

    ## ------ LOG ----------
    #no log  ####this is real line USE THIS to disable log!!! when commented allows log
    mode http
    option http-buffer-request
    declare capture request len 40000000
    http-request capture req.body id 0
    capture request header user-agent len 150
    capture request header Host len 15
    log-format '{"srcIP":"%[src]","backend":"%s","bIP":"%si","bPORT":"%sp","method":"%[capture.req.method]","user-agent":"%[capture.req.hdr(1),json(utf8s)]","uri":"%[capture.req.uri]","body":"%[capture.req.hdr(0)]"}'

    ## --------------------

This is not exactly what you asked for since it will log all requests not only POST, but you can later grep the log file for "POST", since it saves request method in the log.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.