capture request header <name> len <length>

Capture and log the last occurrence of the specified request header. May be used in sections :

defaults frontend listen backend no no yes yes yes yes no no Arguments :

<name> is the name of the header to capture. The header names are not case-sensitive, but it is a common practice to write them as they appear in the requests, with the first letter of each word in upper case. The header name will not appear in the logs, only the value is reported, but the position in the logs is respected.

<length> is the maximum number of characters to extract from the value and report in the logs. The string will be truncated on the right if it exceeds <length>.

The complete value of the last occurrence of the header is captured. The value will be added to the logs between braces ('{}'). If multiple headers are captured, they will be delimited by a vertical bar ('|') and will appear in the same order they were declared in the configuration. Non-existent headers will be logged just as an empty string. Common uses for request header captures include the "Host" field in virtual hosting environments, the "Content-length" when uploads are supported, "User-agent" to quickly differentiate between real users and robots, and "X-Forwarded-For" in proxied environments to find where the request came from.

Note that when capturing headers such as "User-agent", some spaces may be logged, making the log analysis more difficult. Thus be careful about what you log if you know your log parser is not smart enough to rely on the braces.

There is no limit to the number of captured request headers nor to their length, though it is wise to keep them low to limit memory usage per session.

In order to keep log format consistent for a same frontend, header captures can only be declared in a frontend. It is not possible to specify a capture in a "defaults" section. Example:

capture request header Host len 15
capture request header X-Forwarded-For len 15
capture request header Referer len 15

See also : "capture cookie", "capture response header" as well as section 8 about logging.

results matching ""

    No results matching ""