I assume the issue is with the stream profile rewriting references within the page content from http:// to https://. I expect the app isn’t redirecting with a 30x to google or other external sites.
You can use a negative lookbehind regex to specify the search string in the stream expression. There is an example on the STREAM::enable wiki page (Click here). I’ve added a few more examples to the STREAM::expression page (Click here) as well.
I’m not sure how much drain this would add on CPU and/or memory. If you can positively define what strings you want to rewrite with a simpler regex, it would be less resource intensive.
Also, it would be a good idea to disable the stream filter using STREAM::disable by default and only enable it when the content-type header value matches your test. This ensures that the stream filter isn’t applied to subsequent HTTP responses on the same TCP connection. There is an example of this on most of the stream wiki pages.
I would have thought you could use a stream expression with a single token. Here is a more tested example with the unnecessary backreference in the regex removed:
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]]"
}
The stream portion of the rule should be working fine to only rewrite the http:// references to https:// for *.example.com. The issue is likely to be there isn’t any checking on 30x redirects. If you change this line:
if {[HTTP::is_redirect]}{
To:
if {[HTTP::is_redirect] && [string match -nocase “http://*.example.com*” [HTTP::header value Location]]}{
You can restrict the Location header rewriting to redirects which match http://*.example.com*
If this doesn’t work, try adding logging to the rule, reproduce the issue and then repost your current rule with the logging and the log output from /var/log/ltm. If you have any problems debugging the rule, let us know.
Likewise, using the last rule I posted worked for a test below:
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"}{
log local0. "[IP::client_addr]:[TCP::client_port]: Setting stream expression, enabling filter"
Replace any http:// instance with https:// only if the original string is http://*example.com:
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]]"
}
Here is the log output for a request which was rewritten:
I’m not sure why the rule isn’t working when you’re testing against your application. I would suggest opening a case with F5 Support referencing this post, as the example is working on a simple test in 9.4.4 and should work for your scenario.
On your second point, if you need to only match some subdomains but not all, you could either modify the regex in the stream expression, or add logic to the STREAM_MATCHED event. For the second option, you can check if the matched string is in a list or datagroup of subdomains to not rewrite. In that case, just don’t call STREAM::replace.
Thinking about this again, I’m guessing the reason you were seeing strings being matched which were much longer than a single domain was the regex you were testing with was wrong.
Here is an example that should work to allow you to check all http://*.example.com strings but rewrote only those you want to.
when RULE_INIT {
List of *.example.com subdomains that should not be rewritten (in lowercase)
set ::subddomains_to_preserve [
"keep1.example.com" \
"keep2.example.com" \
"keep3.example.com" \
]
}
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"}{
log local0. "[IP::client_addr]:[TCP::client_port]: Setting stream expression, enabling filter"
Replace any http:// instance with https:// only if the original string is http://*example.com:
STREAM::expression {@http://.*?example\.com@}
Enable the stream filter for this response only
STREAM::enable
}
}
when STREAM_MATCHED {
Check if the current string matched by the stream filter is part of the list of subdomains to preserve.
if {[matchclass [string tolower [STREAM::match]] equals $::subddomains_to_preserve]}{
log local0. "[IP::client_addr]:[TCP::local_port]: found [STREAM::match], but did not modify it."
} else [
log local0. "[IP::client_addr]:[TCP::local_port]: found [STREAM::match], replaced with: [string map {http:// HTTPS://} [STREAM::match]]"
STREAM::replace "[string map {http:// https://} [STREAM::match]]"
}
}
You could also change the list in RULE_INIT from subdomains to preserve to those you want to rewrite to https. The list could also be replaced with a separate class.
Edit: you’ll also want to use an HTTP profile with response chunking set to rechunk.
SOL6422: Using the Stream profile with HTTP traffic can prevent the client from displaying all of the data
Hi everybody, I been copying and pasting the last irule shown here, because I had a similar issue. First I had to modify that irule becouse gave to me some problems whit the syntax and other stuff. I’m new on f5 so I starting to google it how to fix it and finally I got this:
when RULE_INIT {
Lista de los domininios que NO se reemplazaran
set static::listado [ list /http://www.fapesp.br ]
}
when HTTP_RESPONSE {
Desabilitar el filtro stream
STREAM::disable
Check if response type is text
if {[HTTP::header value Content-Type] contains "text"}{
log local0. "[IP::client_addr]:[TCP::client_port]: Setting stream expression, enabling filter"
Remplazar cualquier http:// por https://
STREAM::expression {@http://*@}
Habilitar el filtro stream solo si corresponde
STREAM::enable
}
}
when STREAM_MATCHED {
Revisar if el string actual obtenido por el filtro stream esta en la lista de dominios a conservar
if { [lsearch -glob $static::listado [string tolower [STREAM::match]] ] } {
log local0. "[IP::client_addr]:[TCP::local_port]: found [STREAM::match], but did not modify it."
} else {
log local0. "[IP::client_addr]:[TCP::local_port]: found [STREAM::match], replaced with: [string map {http:// HTTPS://} [STREAM::match]]"
STREAM::replace "[string map {http:// https://} [STREAM::match]]"
}
}
This rule does not works and show this error: " Rule /Common/iRule_Scielo_EXCEPTIONS : 192.168.210.36:19119: found http://, but did not modify it"
So where is my problem, I only want excluding some urls from stream conversion. Thank