# STREAM::expression doesn't seem to work

**URL:** <https://community.f5.com/t/stream-expression-doesnt-seem-to-work/69767>\
**Category:** Technical Forums\
**Tags:** application-delivery\
**Created:** [May 19, 2022, 6:32pm UTC](https://community.f5.com/t/stream-expression-doesnt-seem-to-work/69767 "2022-05-19T18:32:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kevin\_Basler](https://avatars.discourse-cdn.com/v4/letter/k/87869e/32.png) [@Kevin\_Basler](https://community.f5.com/u/Kevin_Basler)\
**Post date:** [May 19, 2022, 6:32pm UTC](https://community.f5.com/t/stream-expression-doesnt-seem-to-work/69767/1 "2022-05-19T18:32:15Z")

</div>

We’ve created an iRule that is supposed to change any occurance of the host [internal.com](http://internal.com) to [external.com](http://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.&nbsp; Here’s the code:

when HTTP\_RESPONSE {

STREAM::disable

if { [HTTP::payload] contains “[internal.com](http://internal.com)”} {  
log local0. “Before if, payload contains : $[HTTP::payload]”  
set oldString “[internal.com](http://internal.com)”  
set newString “[external.com](http://external.com)”  
STREAM::expression @${oldString}@${newString}@@  
STREAM::enable  
log local0. “After if, payload contains : $[HTTP::payload]”  
}  
}

We’ve tried using the hosts [internal.com](http://internal.com) and [external.com](http://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.

---

<div class="post-metadata">

**Author:** ![AlexBCT](https://avatars.discourse-cdn.com/v4/letter/a/b5e925/32.png) [@AlexBCT](https://community.f5.com/u/AlexBCT)\
**Post date:** [May 23, 2022, 7:31pm UTC](https://community.f5.com/t/stream-expression-doesnt-seem-to-work/69767/2 "2022-05-23T19:31:36Z")

</div>

Hi Kevin,

Do you have a compression profile attached to the virtual server? Most web servers will compress HTTP responses by default, which means that when the STREAM profile/irule looks through the return payload, it tries to match the compressed content, which doesn’t contain the strings [internal.com](http://internal.com).

If you don’t have it on the virtual servers, two things you can try;

1. attach a HTTP compression profile on your virtual server, this will offload HTTP compression onto the F5 (and saving a bit of CPU on the web server as well), or;

2. Using an iRule or Local Traffic Policy, remove the Accept-Encoding header from the request before sending it through to the web server. Be aware though that this will now serve up uncompressed pages to the client and may increase bandwidth usage.

I’ve done a quick test on my lab system and this does make your iRule work.

Hope this helps.

Edit: Here’s some more information about the impact of compression on the stream profile:&nbsp;[https://support.f5.com/csp/article/K39394712](https://support.f5.com/csp/article/K39394712)

---

<div class="post-metadata">

**Author:** ![Kevin\_Basler](https://avatars.discourse-cdn.com/v4/letter/k/87869e/32.png) [@Kevin\_Basler](https://community.f5.com/u/Kevin_Basler)\
**Post date:** [May 23, 2022, 8:01pm UTC](https://community.f5.com/t/stream-expression-doesnt-seem-to-work/69767/3 "2022-05-23T20:01:20Z")

</div>

Hey Alex, appreciate the quick reply. I’m just trying to understand this.

If compression was the issue, would I still see the value of HTTP::payload both before and after the STEAM::expression?&nbsp;As I mentioned before, I’m currently seeing the value before and after the stream::expression has run. Unfortunately, it doesn’t seem to be changed.

Thanks,

Kevin

---

<div class="post-metadata">

**Author:** ![AlexBCT](https://avatars.discourse-cdn.com/v4/letter/a/b5e925/32.png) [@AlexBCT](https://community.f5.com/u/AlexBCT)\
**Post date:** [May 24, 2022, 4:22pm UTC](https://community.f5.com/t/stream-expression-doesnt-seem-to-work/69767/4 "2022-05-24T16:22:25Z")

</div>

Well, you would still see a payload, but wouldn’t make any sense. (garbled text) If you did see readable text, then compression indeed wouldn’t be the issue.

Can you tell some more about the payload that you are looking into? E.g. Is it HTML/JSON/JS/etc. and the amount of data per response? And just to confirm, the text “[internal.com](http://internal.com)” is indeed in the payload of the HTTP response rather than the headers?

---

<div class="post-metadata">

**Author:** ![Kevin\_Basler](https://avatars.discourse-cdn.com/v4/letter/k/87869e/32.png) [@Kevin\_Basler](https://community.f5.com/u/Kevin_Basler)\
**Post date:** [May 24, 2022, 7:02pm UTC](https://community.f5.com/t/stream-expression-doesnt-seem-to-work/69767/5 "2022-05-24T19:02:13Z")

</div>

So this is the solution that we arrived at, thanks to you and your suggestion of using&nbsp;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](https://internal.com)”  
set external\_host “[https://external.com](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](http://internal.com)”} {  
log local0. “Before if, payload contains : $[HTTP::payload]”  
set oldString “[internal.com](http://internal.com)”  
set newString “[external.com](http://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!

---

<div class="post-metadata">

**Author:** ![AlexBCT](https://avatars.discourse-cdn.com/v4/letter/a/b5e925/32.png) [@AlexBCT](https://community.f5.com/u/AlexBCT)\
**Post date:** [May 26, 2022, 8:12am UTC](https://community.f5.com/t/stream-expression-doesnt-seem-to-work/69767/6 "2022-05-26T08:12:41Z")

</div>

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. 😉
