Forum Discussion
Desire to view contents of If-Modified-Since & If-None-Match http headers
Using iRule below:
when HTTP_REQUEST {
set rqst_headers [HTTP::header names]
set hsl [HSL::open -proto UDP -pool HIGH_SPEED_LOGGING]
HSL::send $hsl "REQUEST HEADERS = $rqst_headers"
if { [HTTP::header exists If-Modified-Since] }{
set since_modded [HTTP::header value If-Modified-Since]
HSL::send $hsl "If-Modified-Since exists: [HTTP::header If-Modified-Since] CACHE DISCOVERY $since_modded "
}
if { [HTTP::header exists If-None-Match] }{
set none_match [HTTP::header value If-None-Match]
HSL::send $hsl "If-None-Match exists: [HTTP::header If-None-Match] CACHE DISCOVERY $none_match "
}
}
Those headers show up in the request headers list:
REQUEST HEADERS = Accept Referer Accept-Language User-Agent Host If-Modified-Since If-None-Match DNT Connection Cookie
But never catch in the conditional statements. Does anyone see my error?
6 Replies
- VernonWells
Employee
I just tried the following on 11.5.3:
when HTTP_REQUEST { log local0. "headers = [HTTP::header names]" if { [HTTP::header exists If-None-Match] } { log local0. "If-None-Match" } }and with the following request:
GET / HTTP/1.1 Host: If-None-Match: foothe following is logged:
Rule /Common/test : headers = Host If-None-Match Rule /Common/test : If-None-Matchjust as I'd expect.
Can you switch the HSL to local logging (just for debugging; in general, HSL logging is a better production choice)? Can you also verify you see no errors in the log otherwise?
- OTS02
Cirrus
Thanks Vernon. As it turned out, my original code was working, but got missed by the syslog server(because I forgot to put the text string in the log line that the syslog server uses to direct to the correct file). As always, the Devcentral community leads me on to cool discoveries. So when you did the GET/ http/1.1 etc - was that from Curl? - VernonWells
Employee
I used telnet, but you can use curl to add headers (using the -H flag). It's also sometimes helpful to add -V to see all headers in the transaction.
- Jordan_Self_149Historic F5 Account
For logging/modifying specific headers, I find that using a loop is usually the best way to parse through them:
when HTTP_REQUEST { set rqst_headers [HTTP::header names] set hsl [HSL::open -proto UDP -pool HIGH_SPEED_LOGGING] HSL::send $hsl "REQUEST HEADERS = $rqst_headers" foreach request_header [HTTP::header names] { if { $request_header eq "If-None-Match" } { HSL::send $hsl " $request_header = [HTTP::header values $request_header] " } } }The result should be that the If-None-Match header is logged along with the value using this format:
HEADER NAME = HEADER VALUE
Hope this helps!
- OTS02
Cirrus
Thanks Jordan - works very well!
Hi OTS02,
in the past I've seen some really strage behavior, when using unquoted conditions containing "-" signs. Well, it should work, but somehow its doesn't work well everytime...?
when CLIENT_ACCEPTED { set hsl [HSL::open -proto UDP -pool HIGH_SPEED_LOGGING] } when HTTP_REQUEST { HSL::send $hsl "REQUEST HEADERS = [HTTP::header names]" if { [set since_modded [HTTP::header value "If-Modified-Since"]] ne "" } { HSL::send $hsl "If-Modified-Since exists: CACHE DISCOVERY $since_modded " } if { [set none_match [HTTP::header value "If-None-Match"]] ne "" } { HSL::send $hsl "If-None-Match exists: CACHE DISCOVERY $none_match " } }Note: I've tweaked your iRule a little bit to increase its performance. Its now using the CLIENT_ACCEPTED event to define the HSL connection and using a [set since_modded [HTTP::header value "If-Modified-Since"]] ne "" syntax to check for existence ( header ne "" is faster then header exists) and store the results in a single step. Well, the code could be further optimized by skipping the $variable creation at all, but I assume you need to process the results further...
Cheers, Kai
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com