Bug 57710

Summary: Wildcard matching for logging headers
Product: Apache httpd-2 Reporter: Peter Pramberger <peter>
Component: mod_log_configAssignee: Apache HTTPD Bugs Mailing List <bugs>
Status: NEW ---    
Severity: normal Keywords: PatchAvailable
Priority: P2    
Version: 2.4.12   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: Patch for 2.2
Patch for 2.4

Description Peter Pramberger 2015-03-15 14:12:54 UTC
I recently got the requirement to log all X-* headers in some sort of "mass-hosting" setup, where the header names are not known beforehand.

Unfortunately this is something not possible yet. While mod_log_forensic provides the possibility to dump headers, it is limited to all the request headers (sent by client), and which headers to log is not configurable.

So it would be great to allow for the use of wildcards in the %{...}i and %{...}o log formats.

Fortunately find_multiple_headers() in mod_log_config.c does already most of the work required for this, so extending it is not a big issue. Please have a look at the attached patches, they should apply cleanly to the 2.4 and 2.2 branches.

Using wildcards will prefix its header value with the header name, while non-wildcard header names keep the ususal value-only output. For example using LogFormat "\"%{*}o\"" to log all response headers would produce something like this in the access log:

"Vary: User-Agent, Content-Length: 4330, Keep-Alive: timeout=60, max=100, Connection: Keep-Alive, Content-Type: text/html; charset=ISO-8859-1"

Note that I tried to keep the overhead as low as possible for the usual non-wildcard use case, but there is probably room for optimization.

Would be great if you could review the patches (luckily the logging infrastructure in 2.2 and 2.4 is identical in this case) and maybe include them in the 2.2 and 2.4 branches.
Comment 1 Peter Pramberger 2015-03-15 14:13:39 UTC
Created attachment 32571 [details]
Patch for 2.2
Comment 2 Peter Pramberger 2015-03-15 14:14:06 UTC
Created attachment 32572 [details]
Patch for 2.4
Comment 3 Peter Pramberger 2015-03-15 14:35:46 UTC
BTW: It would also be nice to allow for case-insensitive matching, but I've no idea how to encode this in the log format options...