STREAM::expression doesn't seem to work
We've created an iRule that is supposed to change any occurance of the host internal.com to external.com in the payload of the response. We've added some logging steps to confirm that the STREAM::expression doesn't seem to be making the change. Here's the code:
when HTTP_RESPONSE {
STREAM::disable
if { [HTTP::payload] contains "internal.com"} {
log local0. "Before if, payload contains : $[HTTP::payload]"
set oldString "internal.com"
set newString "external.com"
STREAM::expression @${oldString}@${newString}@@
STREAM::enable
log local0. "After if, payload contains : $[HTTP::payload]"
}
}
We've tried using the hosts internal.com and external.com in the stream expression instead of variables, several variations with brackets, quotes and nothing seem to make any difference. We do have the stream profile assigned to the VS.
Any suggestions would be appreciated.
So this is the solution that we arrived at, thanks to you and your suggestion of using HTTP::header remove "Accept-Encoding". I've removed it and it fails just like before. Add it back in and everythign is working.
when HTTP_REQUEST {
HTTP::header remove "Accept-Encoding"
}when HTTP_RESPONSE {
if { [HTTP::header exists "Location"] }{
set internal_host "https://internal.com"
set external_host "https://external.com"
if { [HTTP::header "Location"] contains $internal_host } {
HTTP::header replace "Location" [string map "$internal_host $external_host" [HTTP::header "Location"]]
}
}
STREAM::disable
if { [HTTP::payload] contains "internal.com"} {
log local0. "Before if, payload contains : $[HTTP::payload]"
set oldString "internal.com"
set newString "external.com"
STREAM::expression @$oldString@$newString@@
STREAM::enable
log local0. "Before if, payload contains : $[HTTP::payload]"
}
}Something that is interesting is that I'm seeing readable payload both before and after using HTTP::header remove "Accept-Encoding" in the HTTP_REQUEST section. I can't explain it, but the important part is we have a working solution.
Thanks for all of your help, Alex! Really appreciate it!
Hi Kevin,
Great to hear! Indeed interesting as to why this didn't work beforehand, but at least it's working now. Also thanks for posting to solution, I'm sure someone else will come across it and be happy with it as well. 😉