Forum Discussion
karthik_sriniva
Nimbostratus
Oct 28, 2005Stream Profile: Replace String
Hi Guys,
I had configured a virtual server for our secure site. The content is legacy code and it has hardcoded urls for http. Currently I am using stream profile to replace all the http:// to https://
The code also contains javascript which has hardcoded http%3A%2F%2F, which should be replaced with https%3A%2F%2F. Is there a way to make stream profile perform this replacement as well.
Thanks for your help as always
Srini
23 Replies
- bl0ndie_127134Historic F5 AccountYou need to either escape or use a different expression separator. The example below uses the character '' as the expression separator.
/uri1/uri2//uri3/uri4/ - Brian_Gupta_115
Nimbostratus
Am I missing something? How are you setting the expression separator? (Is this set in the profile?)
-Brian - Brian_Gupta_115
Nimbostratus
Also, what is the default context of STREAM_REPLACED?
Thanks,
Brian - Brian_Gupta_115
Nimbostratus
STREAM::replace [] - Can be used to change the target replacement string specified in the profile. This call is not sticky and will be applied only once during the current match. If the ‘target’ expression is missing, the replacement will be skipped.
Does this mean that if I execute "STREAM::replace" without any arguements, the stream profile default action won't take effect?
Thanks,
Brian - karthik_sriniva
Nimbostratus
Thanks for the information. I tried with and this is the error I am getting when I try to update the stream profile
Bad Characters. Only the following special characters are allowed: period, asterisk, forward slash, dash, colon, underscore, question mark, equals, at sign, comma, ampersand and space (.*/-:_?=@,&
/http://testbigip/https://testbigip/ - bl0ndie_127134Historic F5 AccountThe configuration is still handled from the stream profile. Adding the expression to the ‘target’ profile value and leaving the ‘source’ empty triggers the new behavior.
Calling STREAM::replace without any arguments will skip the replacement.
The new event is stream STREAM_MATCHED and can be fired both on the client and/or server side depending on your profile configuration.
Finally, the *first* character of the expression is treated as the expression separator. If you are having trouble with the ‘’ character, give this a try @/http://testbigip@https://testbigip/@ - Doug_24189
Nimbostratus
I have found something like this seems to work for replacing multiple items within a stream
when HTTP_RESPONSE {
STREAM::enable
STREAM::expression @IE@Apache@@Windows@Linux@
}
This would replace IE with Apache and Windows with Linux
9.2 is required as well as a stream profile defined within the Virtual Server. Just a blank stream profile works. - Hamish
Cirrocumulus
Hmm...
Is there any way to make the replacement sting a variable (e.g. [HTTP::header host])
H - hoolio
Cirrostratus
Hi Hamish,
Yes, STREAM::expression accepts variables. Just make sure to wrap the string in double quotes instead of curly braces.
Also, I think you'll need to save the HTTP::host value in HTTP_REQUEST. And it would be good to only enable the stream filter for text responses when the client used a host header.
http://devcentral.f5.com/Wiki/default.aspx/iRules/STREAM__expression.htmlwhen HTTP_REQUEST { Save the host header value set host [HTTP::host] } 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" && $host ne ""}{ Replace any instance of the requested with newhost.example.com STREAM::expression "@$host@newhost.example.com@" Enable the stream filter for this response only STREAM::enable } }
Aaron - Hamish
Cirrocumulus
Ah. Thanks.
FWIW after asking the question I found the rather excellent ProxyPass iRule in the codeshare... Brilliant piece of code.
I also found that variables are shared between iRules for a single connection... Ouch... I wasn't expecting that feature...
H
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
