Forum Discussion
Anthony_Vaz_547
Nimbostratus
Jul 07, 2009Stream::expression irule problem
Hi guys
I'm sure this is just me being an airhead but I can't get this irule to work. Any input greatly appreciated
We have a need to rewrite the content of a HTTP response. I am searching for what I want to find (which is "top.") and replacing it (with "top.child1.")
This is the irule code for the above (and this works).
When HTTP_RESPONSE {
Disable the stream filter by default
STREAM::disable
Check if response type is text
if {[HTTP::header value Content-Type] contains "text"}{
Replace any "top. instance with self.
STREAM::expression "@top\.@top.child1.@"
Enable the stream filter for this response only
STREAM::enable
}
}
However, annoyingly, there are occassions when "top." is too generic. There are a number of IMG SRC tags that end in top.jpg. Therefore, those image tags are being rewritten to top.child1.jpg.
I would like to have an "unless" stream expression. The STREAM::expression wiki page suggests that this can be done (http://devcentral.f5.com/wiki/default.aspx/iRules/stream__expression)
I have therefore modified my STREAM::expression to be
STREAM::expression {@top\.(?!jpg)@top.child1.@}
I infer, from the Wiki page, that this expression should always rewrite top. to top.child1. unless the original string is top.jpg
However this doesn't work - Can anyone help me out with what the correct syntax should be?
Many thanks in advance
- hoolio
Cirrostratus
That looks about right. The regex doesn't match top.jpg:http://devcentral.f5.com/wiki/default.aspx/iRules/stream__expression when HTTP_RESPONSE { Disable the stream filter by default STREAM::disable Check if response type is text if {[HTTP::header value Content-Type] contains "text"}{ Match any http:// instance and replace it with nothing STREAM::expression {&http://.*?example\.com&&} Enable the stream filter for this response only STREAM::enable } } when STREAM_MATCHED { log local0. "[IP::client_addr]:[TCP::local_port]: matched: [STREAM::match],\ replaced with: [string map {http:// https://} [STREAM::match]]" STREAM::replace "[string map {http:// https://} [STREAM::match]]" }
- Anthony_Vaz_547
Nimbostratus
Thanks Aaronwhen HTTP_RESPONSE { Disable the stream filter by default STREAM::disable Check if response type is text if {[HTTP::header value Content-Type] contains "text"}{ Match any 'top.' instance and replace it with nothing STREAM::expression {&top\.(?!jpg)&&} Enable the stream filter for this response only STREAM::enable } } when STREAM_MATCHED { if {[STREAM::match] contains "jpg"} { return } else { STREAM::replace "[string map {top. top.child2.} [STREAM::match]]" } }
- hoolio
Cirrostratus
That's odd... regexp handles this correctly in an iRule:when RULE_INIT { log local0. "\[regexp -inline -all {top\.(?!jpg)} top.test\]: [regexp -inline -all {top\.(?!jpg)} top.test]" log local0. "\[regexp -inline -all {top\.(?!jpg)} top.jpg\]: [regexp -inline -all {top\.(?!jpg)} top.jpg]" }
when RULE_INIT { log local0. "\[regexp -inline -all {(top\.(?:?!jpg))} top.jpg\]: [regexp -inline -all {(top\.(?:?!jpg))} top.jpg]" }
- Anthony_Vaz_547
Nimbostratus
Thanks ever so much for your help - will get a call raised and will add the results onto this thread
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