Skip to content

Instantly share code, notes, and snippets.

@lazywithclass
Created February 20, 2017 02:25
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lazywithclass/f8615742e876237a051eb64476fd71dd to your computer and use it in GitHub Desktop.
Save lazywithclass/f8615742e876237a051eb64476fd71dd to your computer and use it in GitHub Desktop.
Logging request body in HAProxy

Logging request body in HAProxy

On the 14th of October HAProxy 1.6 was released! Among all features announced I am particularly interested in the ability to log the body of a request.

It wasn't straightforward for me to understand how to do that, which is why I'm blogging it.

The relevant part could be found in the "Captures" section of the announcement, this is how I changed it to suit my needs:

# you need this so that HAProxy can access the request body
option http-buffer-request
# declare a capture slot giving it a max length (400) and a reference (0)
declare capture request len 400
http-request capture req.body id 0
# log it
log-format {"%[capture.req.hdr(0)]"}

I've create a small configuration file that could help you start experimenting with this feature.

By default it will also be logged in the %hs variable, have a look at the docs section about logging for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment