A user wanted to offload some cache control manipulation from the webserver configuration onto the BIG-IP via iRules. Since this is just HTTP header settings it should be fairly straightforward. We'll, almost...

Trying to write an IRule to make client computers not cache certain file types. We can not have our client computers download any files that start with "slide" or "ps" into their temporary internet files.

I have tried the following however the files are still caching into the Temp internet files.

when HTTP_REQUEST {
  if {[HTTP::uri] contains "slide."} {
    set foundmatch 1
  }
  if {[HTTP::uri] contains "ps."} {
    set foundmatch 1
  } else {
    set foundmatch 0
  }
}
when HTTP_RESPONSE {
  if {$foundmatch == 1} {
    HTTP::header replace Cache-Control no-cache
    HTTP::header replace Pragma no-cache
  }
}

We'll after a bit of packet sniffing it was determined that the browser wasn't honoring the headers since the default response was HTTP/1.0. Fortunately you can easily change this in iRules with the HTTP::version command.

Here's the completed iRule.

when HTTP_REQUEST {
  set foundmatch 0
  if { ([HTTP::uri] contains ".swf") or ([HTTP::uri] contains "ps")} {
    set foundmatch 1
  }
}

when HTTP_RESPONSE {
  if {$foundmatch == 1} {
    HTTP::version "1.1"
    HTTP::header replace Pragma no-cache
    HTTP::header replace Cache-Control no-cache
    HTTP::header replace Expires -1
    HTTP::header remove Connection
    HTTP::header insert Connection Close
  }
}

So, the lesson here is to remember to upgrade the version to 1.1 if you want the browser to honor the no-cache directives B-).

Click here to access the original forum thread.

-Joe

[Listening to: The Boxer - Simon & Garfunkel - Concert in Central Park (06:03)]