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

This rule is in the wiki, so it seems HTTP::header is valid within CACHE_REQUEST (although the wiki does not definitively call this out):

when CACHE_REQUEST {
 if { [HTTP::header "Content-Length"] equals "0" } {
  CACHE::expire
  log local.tooshort
 }
}

Is your logging working and what does it show?

Denny

Uh … why don’t you just set the minimum object size to be a non zero value in the ramcache http profile?

Well, there are two reasons…

Firstly, the minimum size value does not seem to work every time. It works most times, but for unexplained reasons I still see zero length, or close to it, pages that have the "Age: " header that is inserted by the BigIP.

Secondly, the end goal is not to just look for zero length pages. We have some important pages that might be partially cached downstream from the BigIP, which the BigIP sees as okay and caches as well. Then we have a difficult time clearing all the different points. If I can look for certain headers I can use an iRule expire these pages and keep it dynamic.

An example operation might be, ‘if content-length > 50’ on a page that is known to be 100.

The logic for calculating the min size is pretty darn simple. If the minimum size is not working then its a bug. Do you have responses that don’t have a content length header (just ‘Connection: close’)? Can you open a support case so that I can peek at the packet captures for the cases where it does not work?

Now if you have a more complicated logic, I suggest that you use CACHE::disable in HTTP_RESPONSE event to prevent the response from being added to the cache in the first place. You will also want to add a ‘Cache-Control: no-cache’ header to prevent it from being cached down stream.

Sorry, here is an example. I have “Minimum Object Size” set to 500 bytes yet I still receive the following page.

Profile my_profile
|   URI /blank.htm
|   Host www.my.com
|   16 hits   Size 208
|   Received 2007-02-12 14:44:09   Last sent 2007-02-12 14:44:12
|   Expires 1969-12-31 16:00:00   Vary none   Vary count 1
[root@bigip1:Active] config
http://www.my.com/blank.htm
GET /blank.htm HTTP/1.1
Host: www.my.com
User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
HTTP/1.x 200 OK
Connection: Keep-Alive
Date: Mon, 12 Feb 2007 22:45:55 GMT
Age: 106
Content-Length: 6
Server: Apache-Coyote/1.1
Etag: W/"6-1169519270000"
Last-Modified: Tue, 23 Jan 2007 02:27:50 GMT
Content-Type: text/html

Do you by any chance have defined an cache uri include that will match ‘/blank.htm’? The URI includes take precedence over all the configuration and will force the document to get cached regardless of the mix/max water marks. Otherwise go ahead and open a support case and we will look at it.

Posted By bl0ndie on 2/12/2007 2:51 PM

The logic for calculating the min size is pretty darn simple. If the minimum size is not working then its a bug. Do you have responses that don’t have a content length header (just ‘Connection: close’)? Can you open a support case so that I can peek at the packet captures for the cases where it does not work?

Now if you have a more complicated logic, I suggest that you use CACHE::disable in HTTP_RESPONSE event to prevent the response from being added to the cache in the first place. You will also want to add a ‘Cache-Control: no-cache’ header to prevent it from being cached down stream.

The problem with this is that I want these things to be cached by the bigip _and_ by other mechanisms, but it would also be nice to have logic in place that would notice an abnormality and force a re-evaluation to minimize known problems.

Posted By bl0ndie on 2/12/2007 2:58 PM

Do you by any chance have defined an cache uri include that will match ‘/blank.htm’? The URI includes take precedence over all the configuration and will force the document to get cached regardless of the mix/max water marks. Otherwise go ahead and open a support case and we will look at it.

The includes, excludes and pins are all empty.

Ticket is opened: c329237

Posted By wschultz on 2/12/2007 3:07 PM

Ticket is opened: c329237

tcpdump and quickview has been sent as well…

Thanks again…

-Wil

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.

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.

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