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
- Minn_62043CirrostratusThere 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!
- 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.
- hooleylistCirrostratusYes, 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?
- 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
- hooleylistCirrostratusCan you try this:
- 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
- hooleylistCirrostratusSorry, no from the LTM command line.
- I've never used SSH to connect the LTM yet. I"ll have to learn that. Are there any quick tutorials on that?
- hooleylistCirrostratusYou can use Putty to connect to the LTM command line:
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