Logging entire POST body with HAProxy?
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?
Haproxy does not have a facility to log POST content or HTTP bodies.
Use Wireshark instead.
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
# ...
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.