Forum Discussion
Moe_Jartin
Cirrus
Feb 08, 2010Conditional stream rewrite based on requested uri
I want to rewrite some content based on the uri that is requested. I started with:
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::uri]] {
/uri1* -
/uri2* {
snatpool SNAT_DMZ
pool pool_www.mysite.org_URI1
}
/testlink* {
snatpool SNAT_APZ
STREAM::expression "@http://www.mysite.org@https://www.mysite.org@"
STREAM::enable
pool pool_www.mysite.org_TESTLINK
}
}
}
But then I realized that was only rewriting the request content and NOT the response content. So I need to catch/log the requested uri in a variable and only rewrite the content in the responses to the /testlink uri. Her is my attempt a pieceing together some examples I have found on the forum.
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::uri]] {
/uri1* -
/uri2* {
snatpool SNAT_DMZ
pool pool_www.mysite.org_URI1
}
/testlink* {
snatpool SNAT_APZ
set requested-uri {[HTTP::uri]}
pool pool_www.mysite.org_TESTLINK
}
}
}
when HTTP_RESPONSE {
if {$requested-uri starts_with "/testlink"} {
STREAM::expression "@http://www.mysite.org@https://www.mysite.org@"
STREAM::enable
} else {
STREAM::disable
}
}
So my question is, Is a variable set during the HTTP_REQUEST event available under the HTTP_RESPONSE event? I have not been able to test this as this is a semi-production app.
Thanks,
Joe
- hoolio
Cirrostratus
Hi Joe,when HTTP_REQUEST { switch -glob [string tolower [HTTP::uri]] { /uri1* - /uri2* { set check_response 0 snatpool SNAT_DMZ pool pool_www.mysite.org_URI1 } /testlink* { snatpool SNAT_APZ set check_response 1 pool pool_www.mysite.org_TESTLINK } } } when HTTP_RESPONSE { if {$check_response} { STREAM::expression "@http://www.mysite.org@https://www.mysite.org@" STREAM::enable } else { STREAM::disable } }
- Moe_Jartin
Cirrus
Aaron,switch $check_response { 1 { STREAM::expression "@http://host1@https://host1@" STREAM::enable } 2 { STREAM::expression "@http://host2@https://host2@" STREAM::enable } 3 { STREAM::expression "@http://host3@https://host3@" STREAM::enable } default { STREAM::disable } }
- hoolio
Cirrostratus
Hi Joe,when HTTP_REQUEST { Unset the stream_expr variable if it exists already if {[info exists stream_expr]}{ unset stream_expr } Check the requested URI switch -glob [string tolower [HTTP::uri]] { /uri1* - /uri2* { set stream_expr "@http://www.mysite.org@https://www.mysite.org@" snatpool SNAT_DMZ pool pool_www.mysite.org_URI1 } /uri3* - /uri4* { set stream_expr "@http://www.mysite4.org@https://www.mysite4.org@" snatpool SNAT_DMZ pool pool_www.mysite.org_URI4 } /uri5* - /uri6* { snatpool SNAT_DMZ pool pool_www.mysite.org_URI4 } /testlink* { set stream_expr "@http://www.mysite.test.org@https://www.mysite.test.org@" snatpool SNAT_APZ pool pool_www.mysite.org_TESTLINK } } } when HTTP_RESPONSE { if {[info exists stream_expr]} { STREAM::expression $stream_expr STREAM::enable } else { STREAM::disable } }
- Moe_Jartin
Cirrus
Beautiful!! Does that qualify as a Nerd Alert if I think an iRule is beautiful?? Thanks a ton!
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