Forum Discussion
Ken_Wong_48678
Sep 20, 2005Historic F5 Account
change content type by irule
Hi guys,
I have written a test irule to change the content type of a specific page. I would like to change the content type of main.css from text/css to application/x-javascript.
In HTTP_REQUEST part, I can successfully to check the existence of the page and set a parameter.
But, in the HTTP_RESPONSE part, the parameter seems cannot maintain. Therefore, the content type cannot changed. Anyone can point out any problems in my rule? Thanks!
Regards,
Ken
------------------------------------------------------
when HTTP_REQUEST {
if {[HTTP::uri] contains "main.css"} {
set par 1
log local0. "par is $par"
}
set par 0
pool test_pool
}
when HTTP_RESPONSE {
set ct1 "application/x-javascript"
set ct [HTTP::header "Content-Type"]
log local0. $ct
if { $par == 1 } {
HTTP::header replace "Content-Type" $ct1
}
}
- When creating variables that you want to persist across multiple events, you'll need to access them in the global namespace (with the "::" prefix).
when HTTP_REQUEST { set this_variable_is_local 1 set ::this_variable_is_global 1 } when HTTP_RESPONSE { This will fail as this_variable_is_local isn't defined in this scope if { [info exists this_variable_is_local] } { if { $this_variable_is_local == 1 } { } } This should succeed. if { [info exists ::this_variable_is_global] } { if { $::this_variable_is_global == 1 } { log local0. "Found this_variable_is_global" } } }
- Brian_Gupta_115Nimbostratus1) Are these truly global? IE: Can I access them from different VIPS/rules/etc? (vs. multiple iterations of the same irule)
- I'll try to answer these one by one:
- drteeth_127330Historic F5 AccountYes, they are truly global.
- unRuleY_95363Historic F5 AccountI think the original problem was simply that your HTTP_REQUEST event is always resetting par back to 0.
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