Cole_Libby_1665
Feb 01, 2007Altostratus
Reverse Proxy
Hi,
I'm trying to use irules to make a reverse proxy from an LTM. User connects to a portal server defined as a pool. I scrub the data coming back and rewrite all URLs to use the F5 and remember the original url in a query.
When the user clicks on a URL, the F5 reads the original URL, attempts to rewrite the URI and set the host to the original hostname. It then does a name lookup and attempts to forward the request to the original server in the URL.
Trouble is:
1.) The host in the header doesn't seem to get rewritten
2.) The F5 does seem to forward the request to the correct node.
Here's the HTTP_REQUEST code. (I know there's a better way to parse the URI. just haven't cleaned that up yet.) Suggestion appreciated.
when HTTP_REQUEST {
Don't allow data to be chunked
log local0. "in request - Cole"
if { [HTTP::version] eq "1.1" } {
if { [HTTP::header is_keepalive] } {
HTTP::header replace "Connection" "Keep-Alive"
}
HTTP::version "1.0"
}
if uri = pxy?orig_url then get new url, set host, set uri
if { [HTTP::query] starts_with "orig_url"} {
set qry [lindex [split [HTTP::query] '"="] 1]
set newhost [getfield $qry "/" 3]
log local0. "newhost&uri"
log local0. $newhost
set index [string first $newhost $qry]
set strlen [string length $newhost]
set uindex [expr $index + $strlen ]
set newuri [string range $qry $uindex end]
log local0. "$newuri"
HTTP::header replace "Host" $newhost
HTTP::uri $newuri
log local0. "Host = [HTTP::host]"
log local0. "Newhost = $newhost"
NAME::lookup $newhost
}
}
when NAME_RESOLVED {
log local0. "noding"
log local0. $newhost
log local0. [NAME::response]
node [NAME::response] 80
}