Reamer
March 19, 2024, 8:58am
1
Dear HAProxy community,
I have a problem with the logging of captured response headers when a redirect is performed by HAProxy.Here is a small configuration (HAProxy version is 2.9.6-9eafce5) .
global
log stdout format raw local0
defaults
log global
mode http
log-format "%ci:%cp [%t] %ft %b/%s %sslv %sslc %TR/%Tw/%Tc/%Tr/%Td/%Ta %Th/%Ti/%Ta/%Tt %ST %B %U %CC %CS %tsc %ac/%fc/%bc/%sc/%rc %sq/%bq %hr %hs %{+Q}r"
frontend example
bind *:80
mode http
capture request header user-agent len 100
capture response header Location len 15
acl is_android req.fhdr(user-agent) -i -m reg android\s(9|\d{2})[;|)]
acl is_ios req.fhdr(user-agent) -i -m reg (iphone|ipod|ipad).*os\s(1[4-9]|[2-9]\d)_
http-request redirect code 302 location https://kernel.org if is_ios
http-request redirect code 302 location https://wikipedia.org if is_android
http-request redirect code 302 location https://www.fsf.org if !is_android !is_ios
Actual Log Line:
10.255.0.1:40272 [18/Mar/2024:16:18:22.794] example example/<NOSRV> - - 0/-1/-1/-1/-1/0 0/0/0/0 302 100 82 - - LR-- 1/1/0/0/0 0/0 {curl/7.81.0} {} "HEAD / HTTP/1.1"
As you can see, there are empty brackets before the HEAD. How do I get the location to appear there?
Expected Log Line:
10.255.0.1:40272 [18/Mar/2024:16:18:22.794] example example/<NOSRV> - - 0/-1/-1/-1/-1/0 0/0/0/0 302 100 82 - - LR-- 1/1/0/0/0 0/0 {curl/7.81.0} {https://www.fsf.org} "HEAD / HTTP/1.1"
Reamer
April 2, 2024, 8:44am
2
I suspect a bug in the software, so I opened a GitHub issue.
opened 08:42AM - 02 Apr 24 UTC
type: bug
status: needs-triage
### Detailed Description of the Problem
I have a problem with the logging of … captured response headers when a redirect is performed by HAProxy.
Actual log line
```
10.255.0.1:40272 [18/Mar/2024:16:18:22.794] example example/<NOSRV> - - 0/-1/-1/-1/-1/0 0/0/0/0 302 100 82 - - LR-- 1/1/0/0/0 0/0 {curl/7.81.0} {} "HEAD / HTTP/1.1"
```
### Expected Behavior
Expected log line
```
10.255.0.1:40272 [18/Mar/2024:16:18:22.794] example example/<NOSRV> - - 0/-1/-1/-1/-1/0 0/0/0/0 302 100 82 - - LR-- 1/1/0/0/0 0/0 {curl/7.81.0} {https://www.fsf.org} "HEAD / HTTP/1.1"
```
### Steps to Reproduce the Behavior
1. Place the attached HAProxy configuration in an empty folder.
2. Run `docker run -d --name my-running-haproxy -v .:/usr/local/etc/haproxy:ro -p8080:80 --sysctl net.ipv4.ip_unprivileged_port_start=0 haproxy`
3. Run `curl -I localhost:8080`
4. Check the log `docker logs my-running-haproxy`
### Do you have any idea what may have caused this?
Unfortunately not.
### Do you have an idea how to solve the issue?
_No response_
### What is your configuration?
```haproxy
global
log stdout format raw local0
defaults
log global
mode http
log-format "%ci:%cp [%t] %ft %b/%s %sslv %sslc %TR/%Tw/%Tc/%Tr/%Td/%Ta %Th/%Ti/%Ta/%Tt %ST %B %U %CC %CS %tsc %ac/%fc/%bc/%sc/%rc %sq/%bq %hr %hs %{+Q}r"
frontend example
bind *:80
mode http
capture request header user-agent len 100
capture response header Location len 15
acl is_android req.fhdr(user-agent) -i -m reg android\s(9|\d{2})[;|)]
acl is_ios req.fhdr(user-agent) -i -m reg (iphone|ipod|ipad).*os\s(1[4-9]|[2-9]\d)_
http-request redirect code 302 location https://kernel.org if is_ios
http-request redirect code 302 location https://wikipedia.org if is_android
http-request redirect code 302 location https://www.fsf.org if !is_android !is_ios
```
### Output of `haproxy -vv`
```plain
HAProxy version 2.9.6-9eafce5 2024/02/26 - https://haproxy.org/
Status: stable branch - will stop receiving fixes around Q1 2025.
Known bugs: http://www.haproxy.org/bugs/bugs-2.9.6.html
Running on: Linux 5.15.0-101-generic #111-Ubuntu SMP Tue Mar 5 20:16:58 UTC 2024 x86_64
Usage : haproxy [-f <cfgfile|cfgdir>]* [ -vdVD ] [ -n <maxconn> ] [ -N <maxpconn> ]
```
### Last Outputs and Backtraces
_No response_
### Additional Information
_No response_
Reamer
April 2, 2024, 12:43pm
3
This solution is working. Thanks to @willy and @capflam
global
log stdout format raw local0
defaults
log global
mode http
log-format "%ci:%cp [%t] %ft %b/%s %sslv %sslc %TR/%Tw/%Tc/%Tr/%Td/%Ta %Th/%Ti/%Ta/%Tt %ST %B %U %CC %CS %tsc %ac/%fc/%bc/%sc/%rc %sq/%bq %hr %hs %{+Q}r"
frontend example
bind *:80
mode http
capture request header user-agent len 100
declare capture response len 20
http-after-response capture res.hdr(Location) id 0
declare capture response len 20
http-after-response capture res.hdr(Content-length) id 1
acl is_android req.fhdr(user-agent) -i -m reg android\s(9|\d{2})[;|)]
acl is_ios req.fhdr(user-agent) -i -m reg (iphone|ipod|ipad).*os\s(1[4-9]|[2-9]\d)_
http-request redirect code 302 location https://kernel.org if is_ios
http-request redirect code 302 location https://wikipedia.org if is_android
http-request redirect code 302 location https://www.fsf.org if !is_android !is_ios