Forum Discussion
Nicolas_MENOUX_
Nimbostratus
Apr 29, 2009STREAM_MATCHED for regexp replace ?
Hi,
I'm using an IRule to replace Http content coming from our web servers in order to change image relative path to absolute path as described below :
when HTTP_REQUEST {
set host [HTTP::host]
}
when HTTP_RESPONSE {
if {[HTTP::status] == 200 and [HTTP::header "Content-Type"] contains "text"} {
if {$host ends_with ".xxxxx.com"}
{
STREAM::expression {@'/images/@'http://media.xxxxx.com/images/@}
STREAM::enable
} elseif {$host ends_with ".yyyyy.com"}
{
STREAM::expression {@'/images/@'http://media.yyyyy.com/images/@}
STREAM::enable
}
}
}
As you could see, I've to duplicate the STREAM::expression for each domain name as I do not know how to insert the $host variable into the replace string.
How could I use a single if statement to get a result like :
{
STREAM::expression {@'/images/@'http://media.$host.com/images/@}
STREAM::enable
}
DO I need to use STREAM_MATCHED context and if yes how to do it please. Thanks for your help,
Best Regards,
Nicolas
5 Replies
- hoolio
Cirrostratus
Hi Nicolas, - Nicolas_MENOUX_
Nimbostratus
thank aaron for your quick answer ;-) - hoolio
Cirrostratus
Just what you had in your original post:when HTTP_REQUEST { set host [HTTP::host] }
when HTTP_REQUEST { Check if the client used a host header if {[string length [HTTP::host]}[ set host [HTTP::host] } else { Use the VIP address instead set host [IP::local_addr] } }
- Nicolas_MENOUX_
Nimbostratus
mmm... I'm sorry I think and I'm sure I was not clear in my previous post :-) Thank you for your answer aaron, but if I want to re-use this $host variable into the stream replacement ? As you said, I could not use the $host within braces in the stream::expression, so could I do the replacement within the stream_matched event to replace the '/images/blablabla by 'http://media.$host.com/images/blablabla ? Do you have a sample to do that ? Stream::replace ? Thanks - hoolio
Cirrostratus
Here the basic idea in one shot:when HTTP_REQUEST { Check if the client used a host header if {[string length [HTTP::host]]}{ set host [HTTP::host] } else { Use the VIP address instead set host [IP::local_addr] } } when HTTP_RESPONSE { Check if the response was a 200 and text if {[HTTP::status] == 200 and [HTTP::header "Content-Type"] contains "text"} { STREAM::expression "@'/images/@'http://media\.$host\.com/images/@" STREAM::enable } STREAM::disable } }
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