Forum Discussion

Kevin_Basler's avatar
Kevin_Basler
Icon for Altostratus rankAltostratus
May 19, 2022

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::exp...
  • Kevin_Basler's avatar
    Kevin_Basler
    May 24, 2022

    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!

     

  • AlexBCT's avatar
    AlexBCT
    May 26, 2022

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