is it possible to log all header to html page
Hi Guys,
I try to use the irule to log all http headers when the request is coming to the VS, and then F5 generate the response page to the client.
I find the rule to log the all header to /var/log/ltm, and it's ok to log all header to /var/log/ltm :
- when HTTP_REQUEST {
- set LogString "Client [IP::client_addr]:[TCP::client_port] -> [HTTP::host][HTTP::uri]"
- log local0. "============================================="
- log local0. "$LogString (request)"
- foreach aHeader [HTTP::header names] {
- log local0. "$aHeader: [HTTP::header value $aHeader]"
- }
- log local0. "============================================="
- }
When i try to combine the another irule to let the F5 send the html, the page only display one header not all headers
The another irule is
when HTTP_REQUEST {
HTTP::respond 200 content {
<html><head><title>Test Page</title></head><body>
Here is your header information
</body></html>
}
}
And i combine two rules
when HTTP_REQUEST {
set LogString "Client [IP::client_addr]:[TCP::client_port] -> [HTTP::host][HTTP::uri]"
log local0. "============================================="
log local0. "$LogString (request)"
foreach aHeader [HTTP::header names] {
HTTP::respond 200 content "
<html>
<head>
<title>Test Page</title>
</head>
<body>
Your Request Header information: </BR>
HTTP method: $HTTP_Method </BR>
HTTP URI: $HTTP_URI </BR>
HTTP Path: $HTTP_Path </BR>
HTTP Query: $HTTP_Query </BR>
HTTP Version: $HTTP_Version </BR>
HTTP Host: $HTTP_Host </BR>
User Agent: $User_Agent </BR>
$aHeader: [HTTP::header value $aHeader]
</body>
</html> "
}
}
How can i combine those two rules to log all header to the response page.
Regards,
Ding
1.You can just add the log local0 in statement in the foreach loop and not write all the headers to "LogString" variable like log local0. "$headerName:[HTTP::header value $headerName]" or you can still use "LogString" but without the "append" as this time it will just take the value of the firt header and log it, then the second and then the 3th header and value and so on.
2.Also you can also research the Split string ?splitChars? to split the string in a list before logging the output "LogString" variable, so that you can make it a list (you add something like "#" after each append of the HTTP header and value and use it as match for the split string) beffore logging it out but the previous example is easyer.
Use of manipulations like "Split string" etc.:
https://devcentral.f5.com/s/articles/irules-101-15-tcl-list-handling-commands
I suggest reading the F5 devcental course on irules, so that you can work better with irules. After that play writting irules and in no time you are good to go as I see you are playng with them but just need some more time.