DukeOf1Cat
DukeOf1Cat

Reputation: 1117

Log HAProxy captured response header in custom format

I have an HAProxy configuration with a custom JSON log-format. I want to capture a specific response header and log it.

However, no matter how I try to capture it, I cannot make it appear in the log.

In my log format I use %[capture.res.hdr(0)] but it only comes up as -. I've also tried %[res.hdr(0)] and %[res.hdr(MyHeader)] but they were not valid configuration and HAProxy failed to start.

I've tried capturing using:

capture response header MyHeader len 50

But it doesn't work. I also tried:

declare capture response len 50
http-response capture res.hdr(MyHeader) id 0

With no success. The %hs format variable works - all the captured headers are logged in a delimited string. But I want to log the headers separately as JSON properties.

What am I doing wrong?

I'm currently using HAProxy 1.8.

Upvotes: 0

Views: 4188

Answers (1)

DukeOf1Cat
DukeOf1Cat

Reputation: 1117

It seems like the combination of having capture response header MyHeader len 50 in the frontend section and %[capture.res.hdr(0)] in the log-format actually works. Turns out I had multiple instances of HAProxy running and only reloaded some of them, so the changes only came through for some requests.

Upvotes: 2

Related Questions