Forum Discussion

Thomas_Schaefer's avatar
Thomas_Schaefer
Icon for Nimbostratus rankNimbostratus
Jan 02, 2013

How to change any occurrence of myhost.company.com to myhost-dr.company.com

Hi all and Happy New Year!

 

 

I have been struggling wth an issue regarding streams and changing text.

 

For disaster recovery testing, I have a set of virtual hosts that are EXACT copies of my production system. So, if the web server on a host responds to myhost.company.com to route the request to the virtual hosted instance, even in DR, I still need to set the HOST header to myhost.company.com even though it is a different IP address (the production site is still running as the real IP address). I made this work a long time ago by adding entries in the DNS such as myhost-dr.company.com and having that route to the DR site. In an iRule, if I see the -DR at the end of the first node of the hostname, I strip that off and change the host header back to the myhost.company.com. That works just fine INBOUND.

 

The only time it causes an issue is if the website asserts the original name in a URL it sends. As long as the site uses relative links, we are fine. The URL of the browser stays myhost-dr.company.com. I have found some servers (the JBOSS ones in particular) are sending out absolute links with myhost.company.com. When the browser gets this, it natually redirects this over to the myhost.company.com site which is production! So, the user that was testing a DR site is now accidentlly testing a production site--bad news!

 

I have tried with limited success to use a STREAM profile to look for any host name (company.com) and check to see if the server has a -dr at the end. If not, I change it to add -dr to the hostname. That works for items in the payload, but not in the headers. Does a STREAM profile act on the headers? I know I can simply iterate through the headers looking for company.com and check the name, but is that all? I assume this would handle the issue, but are there any other places a string can sneak by the STREAM profile or the headers? I cannot think of any but I htought I would check with the group on the scope of the STREAM profile regarding HTTP headers.

 

 

PS BTW, it has never been clear to me if I can use a STREAM profile to add text (changing myhost to myhost-dr. I have read things int he documentation that make me question if the content-length will be correct. Thoughts? I presume a STREAM HAS to allow one to change th elength of the output or it would be of very limited use.

 

Thanks,

 

 

Tom Schaefer

 

3 Replies

  • The stream profile will not apply to HTTP headers but iRule commands could sort this out as you've suggested.

     

     

    You can indeed use the stream profile to add text (through replacement).

     

     

    HTTP Content-Length is automatically updated from v9.4.0.

     

     

    Here's some sample code (note I'm searching for hostname/ not hostname so we don't get a match on hostname-dr;

     

    
    You must assign a Stream profile (with no source or target strings specified) to the Virtual Server before you can use this iRule
    
    when HTTP_REQUEST {
     We don’t want to rewrite requests, only responses
     STREAM::disable
     
     Prevent compressed responses from the server – not required if the 
     compression is offloaded to the BIG-IP
     HTTP::header remove Accept-Encoding
    }
    
    when HTTP_RESPONSE {
     Only modify body data if the response type is text
     if { [HTTP::header value Content-Type] contains "text" } {
    
     Search for instances of hostname/ and replace with hostname-dr/
     @ Is a delimiter at the start and end of each string
     STREAM::expression {@hostname/@hostname-dr/@}
    
     Apply and rewrite response
     STREAM::enable
     }
    }
    
  • Does a STREAM profile act on the headers?it will if http profile is not used.

     

     

    Standard TCP virtual server with no HTTP profile

     

     

    When the Stream profile is applied to a standard TCP virtual server that is not configured with the HTTP profile, the search and replace procedure occurs on the entire data portion of each TCP segment. This applies to both data streams (the data transmitted by the client and the data transmitted by the server).

     

     

    Should such a virtual server process L4 connections encapsulating HTTP requests and responses, the search and replace procedure is performed on both the HTTP headers and the HTTP payload (that is, the entire data portion of each TCP segment).sol8115: Overview of the Stream profile

     

    http://support.f5.com/kb/en-us/solutions/public/8000/100/sol8115.html