Forum Discussion

Wil_Schultz_101's avatar
Wil_Schultz_101
Icon for Nimbostratus rankNimbostratus
Feb 12, 2007

How can I grab an HTTP header on CACHE_REQUEST?

I'm trying to grab [HTTP::header "Content-Length"] to use during CACHE_REQUEST so I can make sure the BigIP does not cache blank pages. I've tried to set a global variable during HTTP::Response and no go. The closest I can seem to find would be to use [CACHE::headers] during CACHE_REQUEST.

What I'm using now, fugly...


when CACHE_REQUEST {
 set cheaders [CACHE::headers]
 if { $cheaders contains "Content-Length\: 0" } {
  log local0.$cheaders
  CACHE::expire
 }
}

What I would like to get closer to... Looks okay, but doesn't seem to work.


when CACHE_REQUEST {
 set cheaders [HTTP::header "Content-Length"]
 if { $cheaders == 0 } {
  log local1.$cheaders
  CACHE::expire
 }
}

Version 9.2.4

15 Replies

  • spark_86682's avatar
    spark_86682
    Historic F5 Account
    While you could work around this with an iRule, I think that just making a configuration change around that bug would work too. In my tests, adding:

    
    ramcache uri exclude /NOURIWILLEVERMATCHTHIS

    to the profile (so it isn't empty anymore, thus avoiding the CR) makes the minimum size start working.
  • Posted By spark on 2/13/2007 4:44 PM

    While you could work around this with an iRule, I think that just making a configuration change around that bug would work too. In my tests, adding:

    
    ramcache uri exclude /NOURIWILLEVERMATCHTHIS

    to the profile (so it isn't empty anymore, thus avoiding the CR) makes the minimum size start working.

    While this is an excellent idea, this did not work for me...

    I added to the profile exclude list, disabled the VIP, reset manually from ramcache, checked ramcache to make sure it was empty, re-enabled the VIP, and my page with content-length= 6 gets cached right away.
  • spark_86682's avatar
    spark_86682
    Historic F5 Account
    Yes, that logs the size for me. For example:

    Feb 14 08:16:45 tmm tmm[6896]: 01220002:6: Rule dontcache : local0.3624

    for a file of 3624 bytes.

    I notice that if the object is still in the cache when I apply the dontcache rule, it still gets served from cache, but with a large Age: header. I need to clear the cache before that rule works.
  • spark_86682's avatar
    spark_86682
    Historic F5 Account
    Wow. That's totally weird. From the timestamps it's clear that the response that was logged (and hence excluded from the cache) was not the same one as the one that was cached. Since the hostname is the same, do you have any other rule that might be doing a CACHE::enable on the same virtual? Presumably you'd have checked for that, though. The only other thing I can think of is if somehow there was no content-length header (e.g. via "Connection: close" or chunked content) for a response then the iRule check wouldn't fire.

    How about a debugging iRule like:

    rule debugcache {
      when HTTP_RESPONSE {
        set size [HTTP::header "Content-Length"]
        if { [HTTP::uri] contains "/blank.htm" } {
          log "Got blank.html of apparent length $size"
        }
      }
    }
  • edit: I should note that I changed the min size to 1000 and rebooted last night...

    Well, that irule isn't valid in its current form. So I changed to:

    
    when HTTP_REQUEST {
     set ::uri [string tolower [HTTP::uri]]
     
    }
    when HTTP_RESPONSE {
     set ::size [HTTP::header "Content-Length"]
     log local0.$::size
     if { $::uri contains "/blank.htm" } {
      log "Got blank.html of apparent length $::size"
     }
    }

    And receive the following logs:

    
    Feb 15 11:54:27 tmm tmm[1013]: 01220002:6: Rule demo.my.com : local0.0
    Feb 15 11:54:27 tmm tmm[1013]: 01220002:6: Rule demo.my.com : Got blank.html of apparent length 0
    Feb 15 11:54:27 tmm tmm[1013]: 01220002:6: Rule demo.my.com : local0.
    Feb 15 11:54:27 tmm tmm[1013]: 01220002:6: Rule demo.my.com : Got blank.html of apparent length 
    Feb 15 11:54:28 tmm tmm[1013]: 01220002: repeated 2 times
    Feb 15 11:54:29 tmm tmm[1013]: 01220002:6: Rule demo.my.com : local0.0
    Feb 15 11:54:29 tmm tmm[1013]: 01220002:6: Rule demo.my.com : Got blank.html of apparent length 0
    Feb 15 11:54:29 tmm tmm[1013]: 01220002:6: Rule demo.my.com : local0.
    Feb 15 11:54:31 tmm tmm[1013]: 01220002: repeated 15 times

    And inside the bigip:

    
    Profile www.my.com_profile
    |   URI /blank.htm
    |   Host demo.my.com
    |   159 hits   Size 202
    |   Received 2007-02-15 11:54:29   Last sent 2007-02-15 11:57:25
    |   Expires 1969-12-31 16:00:00   Vary none   Vary count 1