Forum Discussion

Chris_Phillips's avatar
Chris_Phillips
Icon for Nimbostratus rankNimbostratus
Jan 17, 2012

caching images - ignore HTTP request?

Howdy,

I'm updating some inherited rules to cache images:

when HTTP_REQUEST { set filematch 0  Check if requested URI ends with the cache control file types or  the Content-Type equals any of the cache control content types if { ([class search dit2_cache_control_files_dgl ends_with [HTTP::uri]]) or \ ([class search dit2_cache_control_types_dgl equals [HTTP::header Content-Type]])} { set filematch 1 } } when HTTP_RESPONSE { if { $filematch == 1 } { HTTP::header replace "Cache-Control" "max-age=3600,post-check=3600,pre-check=43200" } }

Firstly I noticed that this rule is checking the Content-Type in the **REQUEST**, which, just to be sure, is nonsense, right?

Secondly, it seems to me that checking the HTTP::uri is pretty pointless when you have the Content-Type available in the response. I'm looking at replacing it with just this:

when HTTP_RESPONSE { if { [class search cache_control_types_dgl equals [HTTP::header Content-Type]] } { HTTP::header replace "Cache-Control" "max-age=3600,post-check=3600,pre-check=43200" } else { HTTP::header replace "Pragma" "no-cache" HTTP::header replace "Expires" "-1" HTTP::header replace "Cache-Control" "no-cache,no-store,must-revalidate" } }

Whilst it can seem "safer" to check the URI, why would you ever need to IF you trust your application to be returning a correct Content-Type header? That is surely much more trustworthy that the requested URI?

1 Reply

  • Hi Chris,

     

     

    See your other post here for replies:

     

    http://devcentral.f5.com/Community/GroupDetails/tabid/1082223/asg/50/aft/2160915/showtab/groupforums/Default.aspx

     

     

    Aaron