Forum Discussion
Chris_Phillips
Jan 17, 2012Nimbostratus
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 cache_control_files_dgl ends_with [HTTP::uri]]) or \
([class search 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?
- Michael_YatesNimbostratusHi Chris,
- Chris_PhillipsNimbostratusWell the positive caching side of things is officially deemed to be working satisfactorily, so it's not in my remit to poke too much on that side of things, RAM Cache is not being used, and won't be. And no sign of WA on this project, no, although I've had a bash at selling it to them!
- hooleylistCirrostratusHey Chris,
- Chris_PhillipsNimbostratusThe content-type check does seem to be well after your involvement with it. Do you ever realistically come across well written web apps which won't provide a highly reliable content-type string?
- Chris_PhillipsNimbostratusThe content-type check does seem to be well after your involvement with it. Do you ever realistically come across well written web apps which won't provide a highly reliable content-type string?
- hooleylistCirrostratusNo. I don't think the client would process the content correctly if the content-type was set incorrectly.
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects