Forum Discussion

RobinsonJA_2717's avatar
RobinsonJA_2717
Icon for Nimbostratus rankNimbostratus
May 19, 2017

iRule to modify http response

Hello all,

Seeking some assistance with modifying a http response from a server back to a client.

Senario is as follows (All web traffic)

  • VS_A answers on 443 and sends to pool members on 9999
  • VS_B answers on 888 and sends to same pool members on 7777
  • When browsing to VS_B, there is a function that is on the site that responds with the public url of VS_A (ex https://www.acme.com:9999) instead of https://www.acme.com and hence causes a timeout because the clients are not able to access that port directly.

I am seeking to remove the port but keep all uri information.

Additionaly

Do I need any specific settings for the VS in order for this to work?

I have http-wxff profile I have sslclient profile I have sslserver profile

am I missing anything obvious?

Update....... I am trying below

I am attempting to modify a server response back to the client. I am attempting to remove the port from the url the client receives while still perserving the case and uri information.

When attempting this I notice no 302 response (Using firefox) and no location information. Seeking help to get this sorted.

when HTTP_REQUEST { Disable the stream filter for requests STREAM::disable

 Remove this header to prevent server from compression response
HTTP::header remove Accept-Encoding

} when HTTP_RESPONSE { set internal_host "xxx.yyy.com" set external_host "boy.girl.com" Rewrite the Location header for redirects if { [HTTP::header exists Location] }{ HTTP::header replace Location [string map "$internal_host $external_host" [HTTP::header Location]] }

 Rewrite the response content using a stream profile if it is text 
if { [HTTP::header Content-Type] contains "text" } { 

     Set the stream expression with the find/replace strings 
    STREAM::expression "@$internal_host@$external_host@" 

     Enable the stream filter 
    STREAM::enable 
} 

}

7 Replies

  • JG's avatar
    JG
    Icon for Cumulonimbus rankCumulonimbus

    "

    there is a function that is on the site that responds with the public url of VS_A
    "

    Was this in the form of an HTTP redirect?

  • Hi,

     

    Try this iRule:

     

    when HTTP_RESPONSE { if { [HTTP::status] equals "302" && [HTTP::header Location] contains ":9999/" } { HTTP::header replace Location [string map {":9999/" ""} [HTTP::header Location]] } }

     

    I hope it helps.

     

    Cheers!

     

  • There is an option that when selection responds with the location on another url on a specific port.

     

  • JG's avatar
    JG
    Icon for Cumulonimbus rankCumulonimbus

    If it is an HTTP redirect, you can edit your HTTP profile and select "All" for "Redirect Rewrite".

     

  • JG's avatar
    JG
    Icon for Cumulonimbus rankCumulonimbus

    Try this one then:

    when HTTP_RESPONSE {
        if { [HTTP::header exists "Location"] } {
            log local0. "Original Location: [HTTP::header Location]"                                            
            set new_location [string map {"www.acme.com:9999" "www.acme.com:888"} [HTTP::header value Location]] 
            HTTP::header replace Location $new_location
        }
    }
    
  • Able to resolve using the original iRule. Had a tired brain in messing with wrong virtual servers. Thanks all for you assistance.