Forum Discussion

ramann_75062's avatar
ramann_75062
Icon for Nimbostratus rankNimbostratus
Apr 08, 2010

Replace a header value with stream

hi@all,

 

 

i try to replace a part of a header value with STREAM

 

 

In the response, i get a 302 back. in this 302er I want to replace the protocol.

 

 

Example:

 

Location: http://www.myserver.com/dynamic-data0815

 

-->

 

Location: https://www.myserver.com/dynamic-data0815

 

 

My iRule:

 

--------------------

 

when HTTP_RESPONSE {

 

 

Need to explicitly disable the stream profile by default so it doesn't stay

 

enabled for subsequent HTTP requests on the same TCP connection.

 

STREAM::disable

 

 

Apply stream profile against text responses from the application

 

if { [HTTP::header value Content-Type] contains "text" }{

 

 

Look for http:// and replace it with https://

 

STREAM::expression {@http://@https://@}

 

 

Enable the stream profile

 

STREAM::enable

 

}

 

}

 

This section only logs matches, and should be removed before using the rule in production.

 

when STREAM_MATCHED {

 

log local0. "Matched: [STREAM::match]"

 

}

 

 

-------------------------

 

This works fine for all "http" in the body, but not for the header :-(

 

 

Version: BIG-IP 10.1.0 Build 3341.0 Final

 

 

Thanks for hints

 

bjoern

 

 

 

 

 

1 Reply

  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    A stream profile is only applied against the payload. So if you have a TCP VIP, a stream profile would apply against the TCP payload. The TCP payload could be made up of HTTP headers and an HTTP payload. If you add an HTTP profile to the VIP, then the stream profile is only applied to the HTTP payload.

    To rewrite the Location header in redirects from http:// to https:// you could create a custom HTTP profile with Rewrite Redirects enabled. Or if you want to do this in an iRule you could use something like this:

    
    when HTTP_RESPONSE { 
     
        Rewrite the Location header for redirects from http:// to https://
       if {[HTTP::is_redirect]}{
          HTTP::header replace Location [string map -nocase "http:// https://" [HTTP::header Location]]
       }
    }
    

    Aaron