Quantcast



Docs


Blogs


Forums


Samples


Media


Labs


Resources

 




DevCentral > Weblogs > Joe Pruitt - A Software Architect's take on Network Security
 iRule: prevent caching on certain file types
posted on Wednesday, October 19, 2005 11:11 AM

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)]

Categories:  


Email This
  del.icio.us
      

Feedback


9/11/2007 3:43 PM
Gravatar How could I use this to not cache requests from from a machine?

For instance :
Request URI: http://Server1.usac.mycompany.com/incomingdata/postcgi.exe?prefix=brokerreq/&suffix=.csr
Chuck T.
 Leave Feedback
Title  
Name  
Email
Url
Comments   
Please add 4 and 7 and type the answer here: