Replacing hostname in HTTP RESPONSE header using stream profile and/or Irule
We are trying to allow access from the internet into an internal webserver running on port 8010. The webserver is coded with its internal hostname (host15.mycompany.com:8010) which is only resolvable within the company. We have assigned a public DNS name for the LTM Virtual Server (public.mycompany.com:443) which will terminate SSL and send traffic to the internal pool member of host15.mycompany.com:8010. Since the webserver's HTTP responses all refer to the internal hostname, external users on the internet are unable to resolve the name. Based on my research, it appears that we will need both a STREAM profile for the hostname find/replace as well as an HTTP profile (for SSL, etc). With a simple STREAM profile with the find/replace in the target field and no HTTP profile, the response to the client seems to be properly replaced, but generates a chunking error at the client. Applying an HTTP profile with the Rechunk option, the find/replace stops working, probably due to the fact that the entire TCP segment is no longer being scanned (only the HTTP payload). Is this assumption correct and if so, what are our options ? We have seen several iRule examples and applied the one below along with a HTTP profile with Rechunking, but the client gets a 504 errror despite the fact that the hostame replace seems to be successful. Any ideas ? This is version 10.2
when HTTP_RESPONSE {
set internal_host "host15.mycompany.com:8010"
set external_host "public.mycompany.com:443"
Disable the stream filter by default
STREAM::disable
Check if we're potentially rewriting this response
if {$internal_host ne ""}{
Rewrite the Location header for redirects
if {[HTTP::is_redirect]}{
if {[HTTP::header Location] contains "$internal_hostname"}{
HTTP::header replace Location [string map "$internal_hostname $external_hostname" [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_hostname@$external_hostname@"
Enable the stream filter
STREAM::enable
}
}
}