I’m trying to find/replace a string an an HTTP response body. Here is what I’ve done so far:
Applied the default (empty value) STREAM profile to the relevant virtual-server
Applied an HTTP service profile with Response Chunking set to Rechunck to the virtual-server
Applied the following iRule to the virtual-server
On a packet capture I can see that ‘foo’ string is included in the response body but it is not replaced to ‘bar’ and the STREAM_MATCHED event is not triggered.
LTM version is 10.2.3 Build 112.0 Final.
Is there anything I’m missing here?
when HTTP_REQUEST {
STREAM::disable
}
when HTTP_RESPONSE {
Check if response type is text
if {[HTTP::header value Content-Type] contains "text"}{
log local0. "Content-Type contains text"
Replace foo with bar in the HTTP response body
STREAM::expression {@foo@bar@}
Enable the stream filter for this response only
STREAM::enable
log local0. "Stream enabled"
}
}
when STREAM_MATCHED {
log local0. "matched: [STREAM::match]"
}
The rule looks OK to me. Have you checked that the Content-Type header is present? Do you get any log messages? You could also add ‘log local0. “No Header Match”’ just before the last } of the HTTP_RESPONSE event (on it’s own line) to confirm if there is no header/match.
both of the log lines in the HTTP_RESPONSE are executed so I know the Content-Type is present and contains “text”. I did notice however in the response packet capture that the response has the following header “Content-Encoding: gzip” which suggests that the response is compressed. I’ll try to remove the “Accept-Encoding” from the request and see if that’s the issue.
That’ll be it, assuming it’s the server doing the compression, not the F5. If it is the server, why not move it to the F5 and take some of the load off?
Shouldn’t STREAM::disable be put at the beginning of “when HTTP_RESPONSE”? And it’s hard to see what’s wrong without knowing what the real original/replacement strings look like.
STREAM::disable can be in the HTTP request because they’re part of the same flow. I believe Steve and Yossi have discovered the problem - that the application is compressing the content, so the STREAM iRule can’t see the text.