Forum Discussion

Eric_27859's avatar
Eric_27859
Icon for Nimbostratus rankNimbostratus
Mar 09, 2011

Help with Complete URL Translation iRule

I need an iRule to translate all URLs on Headers and Payloads of Request and Response events.

Let's say that I have one site "public.com" for the clients, and inside on the DMZ network, there are servers with host "inside.corp". Then I need to replace all the HTTP::host with something like:

HTTP::header replace Host "inside.corp"

But my problems come when I need to search in the HTTP::payload to replace all the href="inside.corp/asdf.htm"... or the tag img src="inside.corp/image.jpg" etc URLs...

If I use another iRule to make HTTPS Redirect, and using the same HTTP_REQUEST events, which iRule will be issued first? And in case of HTTP_RESPONSE? I assume that iRules with same events executes in the same order of the Virtual Server Resource list...Could this iRule be like this?

set inside "inside.corp"
set outside "public.com"

when HTTP_REQUEST {
if { [HTTP::host] eq $outside } {
HTTP::header replace Host $inside
if { [HTTP::version] eq "1.1" } {
if { [HTTP::header is_keepalive] } {
HTTP::header replace "Connection" "Keep-Alive"
}
HTTP::version "1.0"
}
  }
}
when HTTP_RESPONSE {
  if { [HTTP::header "Content-Type"] starts_with "text/" } {
  if { [HTTP::header exists "Content-Length"] } {
 set content_length [HTTP::header "Content-Length"]
  if { $content_length > 0 } {
 HTTP::collect $content_length
  }
   }
}
when HTTP_RESPONSE_DATA {  
regsub $inside [HTTP::payload] $outside fixeddata  
    log "Replacing payload with fixed data."  
    HTTP::payload replace 0 $clen $fixeddata  
    HTTP::release 
}

Can I use HTTP 1.1 instead of 1.0 or is better that way?

Thanks a lot!

  • Hi Eric,

     

     

    You can use the ProxyPassv10 iRule to do this:

     

     

    http://devcentral.f5.com/wiki/default.aspx/iRules/ProxyPassV10.html

     

     

    Aaron
  • Thank you very much!

     

     

    It was a nice intro to complex iRules :P

     

     

    It worked really fine!!