Recipe 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}i

Discussion

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 "%{UNIQUE_ID}e \"%{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

  • Recipe 3.15

  • Recipe 3.17



Apache Cookbook
Apache Cookbook: Solutions and Examples for Apache Administrators
ISBN: 0596529945
EAN: 2147483647
Year: 2006
Pages: 215

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net