Some mobile gateways are passing custom headers to my site. These headers are passed in various form开发者_如何学Goats, sometimes, x-msisdn, sometimes x-up-calling-line-id and others. How can I log all headers passed in my custom log format?
Via Apache HTTPD I'm not sure how to log all headers - only how to log one header that you know about.
Using the standard Apache httpd module mod_log_config you can specify the following option in the CustomLog directive.
%{Foobar}i The contents of Foobar: header line(s) in the request sent to the server. Changes made by other modules (e.g. mod_headers) affect this.
However you could do this in jsp (if this is what you're using by chance)
<!-- method used to send request
<%= request.getMethod() %>
URI of the request
<%= request.getRequestURI() %>
<%
/*This method returns an enumeration of all the header names this
request contains.*/
java.util.Enumeration names = request.getHeaderNames();
while (names.hasMoreElements()) {
String hname = (String)names.nextElement();
%>
<%= hname %>
<%= request.getHeader(hname) %>
<%
}
%>
--!>
You can also sniff the network interface to do this.
Wireshark has tshark (apt-get install tshark) tshark 'tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)' -R'http.request.method == "GET" || http.request.method == "HEAD"'
(above came from http://andy.wordpress.com/2008/07/10/sniffing-http/ tshark is the new name for tethereal)
or use something like https://github.com/caesar0301/http-sniffer
精彩评论