Forum Discussion

Vincent_Power_9's avatar
Vincent_Power_9
Icon for Nimbostratus rankNimbostratus
Jun 07, 2005

Rewriting a header inside RESPONSE_DATA

I have an application that uses its local server name when it builds a redirect URL during the authentication phase.

 

 

Example it sends back now

 

location: http://server1.atl.bluecross.ca/funky-uri

 

 

What I want it to send back

 

location: https://www.atl.bluecross.ca/funky-uri

 

 

How could I rewrite this in the RESPONSE_DATA before it makes it back to the client. I would love any help you can give me.

 

  • Basically I'm trying to move from an Apache Reverse Proxy to a BIG-IP, and need to know how to replace the functionality of ProxyPassReverse using iRules.

     

     

    http://httpd.apache.org/docs-2.0/mod/mod_proxy.htmlproxypassreverse

     

     

  • I don't have a box to test this on, but here's a start for you.

     
     when HTTP_RESPONSE { 
       set newhost "www.atl.bluecross.ca" 
       if { [HTTP::header host] eq "server1.atl.bluecross.ca" } { 
         HTTP::header replace host $newhost 
         } 
       } 
     

  • The problem I am having trouble over coming is that I am trying to find a way to basically do the equivalent of "s/http:\/\/server.:8080/https:\/\/bigtest1/" on the location header of the outgoing data. The Apache ProxyPassReverse function handled this for me, and now I need to find a way to duplicate this functionality.

     

     

    Is there a way in iRules to do a search and replace of a header?

     

    The only way I've found to do it is listed below, but it sucks when Error.jsp has a dynamically generated QUERY_STRING.

     

     

    when HTTP_RESPONSE {

     

    if { [HTTP::header location] starts_with "http://server1:8080/app/Error.jsp" } {

     

    HTTP::header replace location https://bigtest1/app/Error.jsp

     

    } elseif { [HTTP::header location] starts_with "http://server2:8080/app/Error.jsp" } {

     

    HTTP::header replace location https://bigtest1/app/Error.jsp

     

    }

     

    }

     

     

  • I think I have it figured out, far this works the way I want.

     
     when HTTP_RESPONSE { 
      
       set gmpHost "http://server1.atl.bluecross.ca:8080/" 
       set ssoHost "http://server2.atl.bluecross.ca:8080/" 
       set bigHost "https://bigtest1.atl.bluecross.ca/" 
       set location [HTTP::header location] 
      
       if { $location starts_with $gmpHost } { 
         regsub -all $gmpHost $location $bigHost newLocation 
         HTTP::header replace location $newLocation 
       } elseif { [HTTP::header location] starts_with $ssoHost } { 
         regsub -all $ssoHost $location $bigHost newLocation 
         HTTP::header replace location $newLocation 
       } 
     } 
     

  • drteeth_127330's avatar
    drteeth_127330
    Historic F5 Account
    You should be able to do this without an iRule. The redirect rewrite option on the HTTP profile should provide the Location header rewrite that you're looking for.