3.17. Logging Arbitrary Request Header Fields
Problem
You want to record the values of arbitrary fields clients send to their request header, perhaps to tune the types of content you have available to the needs of your visitors.
Solution
Use the %{...}i log format variable in your
access log format declaration. For example, to log the Host header,
you might use:
%{Host}iDiscussion
The HTTP request sent by a Web browser can be very complex, and
if the client is a specialized application rather than a browser, it
may insert additional metadata that’s meaningful to the server. For
instance, one useful request header field is the Accept field, which tells the server what
kinds of content the client is capable of and willing to receive.
Given a CustomLog line such as
this:
CustomLog logs/accept_log "\"%{Accept}i\""a resulting log entry might look like this:
PNb6VsCoF2UAAH1dAUo "text/html, image/png, image/jpeg, image/gif,
image/x-xbitmap, */*"This tells you that the client that made that request is
explicitly ready to handle HTML pages and certain types of images,
but, in a pinch, will take whatever the server gives it (indicated by
the wildcard */* entry).
See Also
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access