Forum Discussion
switch not recognizing content type
Hello All,
For some reason my switch is NOT working correctly.
ex)
when HTTP_RESPONSE {
if request is a static file, set cache control to be cached on the client machine for 7 days
if { [HTTP::header exists Content-Type] } {
switch -glob [HTTP::header Content-Type] {
"text/javascript" -
"text/css"-
"image/gif" -
"image/jpeg" } {
HTTP::header replace "Cache-Control" "private, max-age=604800"
}
}
}
Any thoughts why this is happening?
Regards,
TRX
11 Replies
- Minn_62043
Cirrostratus
There should not be "}" after "image/jpeg".when HTTP_RESPONSE { if { [HTTP::header exists Content-Type] } { switch -glob [HTTP::header Content-Type] { "text/javascript" - "text/css"- "image/gif" - "image/jpeg" { HTTP::header replace "Cache-Control" "private, max-age=604800" } } } } - Thanks. That worked!
Regards,
TRX - Colin_Walker_12Historic F5 AccountKeep in mind that these comparisons are case sensitive. It might make sense to include a string tolower along with the switch comparison statement, depending on what piece of data you're switching on and whether or not it can be multi case.
Colin - hoolio
Cirrostratus
Yes, the iRule should work the same in terms of rewriting the headers for HTTPS. Can you check the actual HTTP headers in the responses to see if the cache control header is being set as you expect?
Aaron - It ONLY shows in the HTTP images and NOT HTTPS images.
Here is the code in the SSL VS:
when HTTP_RESPONSE {
if request is a static file, set cache control to be cached on the client machine for 7 daysif { [HTTP::header exists Content-Type] } {switch -glob [HTTP::header Content-Type] {
"text/javascript" -
"text/css" -"image/gif" -"image/png" -"image/jpg" -"image/jpeg" {HTTP::header replace "Cache-Control" "private, max-age=604800"}
}
}
}
Thoughts?
Regards,
TRX
- hoolio
Cirrostratus
Can you try this:
curl -kv https://1.1.1.1/static_content.file
where 1.1.1.1 is the virtual server IP and /static_content.file is the name of a static file?
Aaron - Do you want me to try this in the browser?
Browser info:
https://insidedev.qad.com/vgn-ext-templating/common/styles/vgn-ext-templating.css
HTTP/1.1 200 OK
Date: Fri, 17 Jun 2011 17:24:40 GMT
Server: Microsoft-IIS/6.0
Etag:
X-Powered-By: ASP.NET
Content-Type: text/css
Last-Modified: Mon, 03 Nov 2008 22:17:26 GMT
Content-Language: en-US
Server: WebSphere Application Server/6.1
Connection: Keep-Alive
Regards,
TRX
- hoolio
Cirrostratus
Sorry, no from the LTM command line.
Aaron - I've never used SSH to connect the LTM yet. I"ll have to learn that. Are there any quick tutorials on that?
Also, this is weird that the IRules for HTTPS set cache control response headers on our PRODUCTION site but just NOT our DEVELOPMENT site.
Any reason why would that be? It's go the same IRules and very similar VS/POOL/Members setup.
Thoughts?
Regards,
TRX - hoolio
Cirrostratus
You can use Putty to connect to the LTM command line:
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html -> http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe
Can you try testing from the command line using curl and compare what you see in production with development?
Aaron
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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