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.
Yes but only on 9.2 and later. There are several enhancements worth noting here.
. We added unlimited search and replace target pairs that can be expresses as sed replacement expressions.
. We also added a new event called STREAM_REPLACED where you can query for the matching string and also override the replacement if you desire to do so.
The expression syntax should be fairly familiar to most UNIX users, as it’s a ‘SED’ like replacement pairs of source and targets shown below. expression := /// // //. If the *last* target expression is empty, then a match event will be fired but there will be no replacement performed. The only caveat is that an empty target *must* be specified in the *last* expression. When the filter matches one of the expressions say for example ‘source1’, the matching content will be replaced by ‘target1’.
Configuration :
The new stream behavior can be enabled by applying the new expression to the ‘target’ stream profile and leaving the ‘source’ profile *empty*. If both ‘source’ and ‘target’ values are set, the stream filter will default to the original behavior of looking for string literals.
STREAM_MATCHED - Fired when a when a stream expression matches. This event can be used to skip or change the replacement target.
STREAM::disable - Disables any further processing on the stream filter for this connection. This can be called from HTTP events.
STREAM::enable - Enables the stream filter. This can be called from HTTP events.
STREAM::expression - Replace the stream expression specified in the profile with this value. The syntax is identical to the profile syntax. NOTE that this change affects just this connection and is sticky for the duration of the connection. Use this rule wisely!
STREAM::match - Returns the matching characters.
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.
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 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 (.*/-:_?=@,&
The 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/@
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.
when 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
}
}