Dumping HTTP Headers
From
How to display HTTP headers from server pages. AOL Server, Java Server Pages, Ruby on Rails, PHP, etc.
Contents |
[edit]
Ruby on Rails rhtml code to dump HTTP headers.
The request.env has the HTTP headers prefixed with HTTP_. It also has other environment variables. This code pulls just the items starting with HTTP_ and then strips the HTTP_ portion for easy reading.
<table border="1">
<% for header in request.env.select {|k,v| k.match("^HTTP.*")} %>
<tr>
<td><%=header[0].split('_',2)[1]%></td><td><%=header[1]%></td>
</tr>
<% end %>
</table>
[edit]
AOL Server adp code to dump HTTP headers.
<%
for { set i 0 } { $i < [ns_set size [ns_conn headers]] } { incr i } {
ns_puts "[ns_set key [ns_conn headers] $i]: [ns_set \
value [ns_conn headers] $i]"
}
%>
[edit]
PHP code to dump HTTP Headers
I think the quality/implementation of this code varies depending on how you are running php.
My site uses cgi and I use this
<?php
foreach($_SERVER as $h=>$v)
if(ereg('HTTP_(.+)',$h,$hp))
echo "<li>$h = $v</li>\n";
header('Content-type: text/html');
?>
http://www.tonycode.com/tools/showHTTPHeaders.php
[edit]
JSP/Java code to dump HTTP Headers
<%
out.println("<ul>");
java.util.Enumeration names = request.getHeaderNames();
while (names.hasMoreElements()) {
String name = (String) names.nextElement();
String value = request.getHeader(name);
out.println(" <li> <b>" + name + "=</b>" + value +"</li>");
}
out.println("</ul>");
%>

