Forum Discussion
STREAM::expression regex
I don't think you need to rewrite this:
img src="~/0.jpg"
to the fully qualified URL of this:
img src="http://devcentral.f5.com/0.jpg"
as a local URI of /0.jpg should be rendered using the same hostname the client made the request to.
You might be able to get away with just replacing any instance of ~/ with /. Or maybe /~/ with / and ~/ with / STREAM::expression {@/~/@/@ @~/@@}
when HTTP_REQUEST {
Disable the stream filter by default
STREAM::disable
}
when HTTP_RESPONSE {
Disable the stream filter by default
STREAM::disable
Enable the stream filter for text responses only
if {[HTTP::header value Content-Type] contains "text"}{
Replace '~/' with '/'
STREAM::expression {@~/@/@}
Enable the stream filter for this response only
STREAM::enable
}
}
Or if you want to make the matching more specific and only look within img src tags, you could use something like this:
when HTTP_REQUEST {
Disable the stream filter by default
STREAM::disable
}
when HTTP_RESPONSE {
Disable the stream filter by default
STREAM::disable
Enable the stream filter for text responses only
if {[HTTP::header value Content-Type] contains "text"}{
Match on img src tags with a ~/ in them
STREAM::expression {@]*?~/@@}
Enable the stream filter for this response only
STREAM::enable
}
}
when STREAM_MATCHED {
log local0. "Matched: [STREAM::match], replacing with [string map {~/ /} [STREAM::match]]"
switch -glob [STREAM::match] {
"*~/*" {
Replace ~/ with /
STREAM::replace [string map {~/ /} [STREAM::match]]
}
}
}
If neither of these approaches work, can you reply with the debug logging from /var/log/ltm and give more detail on what hostname the client is requesting and how you want to rewrite the response content?
Aaron
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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