Forum Discussion
krelm_52303
Nimbostratus
Nov 20, 2008Changing HTTP Header Host port
Am receiving http requests on a high port (55555) and need to remove this in the header for all requests (so it sends on as port 80).
For example...
Host: www.google.com:55555 change to Host: www.google.com
Host: www.msn.com:55555 change to Host: www.msn.com
I don't know what all the destinations will be, but need to strip of the 55555 port number from each. Thankfully, I we don't need to rewrite any payload traffic, just this header.
What is the most resource efficient way of achieving this with an irule?
TIA
5 Replies
Sort By
- hoolio
Cirrostratus
Hi there,when HTTP_REQUEST { Replace host header value with everything before the colon HTTP::header replace Host "[getfield [HTTP::host] : 1]" log local0. "[IP::client_addr]:[TCP::client_port]: Replace original host [HTTP::host] with [getfield [HTTP::host] : 1]" }
when HTTP_REQUEST { Check if host value has a colon if {[HTTP::host] contains ":"}{ Replace host header value with everything before the colon HTTP::header replace Host "[getfield [HTTP::host] : 1]" log local0. "[IP::client_addr]:[TCP::client_port]: Replace original host [HTTP::host] with [getfield [HTTP::host] : 1]" } }
when HTTP_REQUEST { Scan the host header value. Save the results to $host and $port if there is a colon in the header value if {[scan [HTTP::host] {%[a-zA-Z_.-]:%d} host port] == 2}{ HTTP::header replace Host $host } }
- krelm_52303
Nimbostratus
Thanks Aaron - great info as ever! - hoolio
Cirrostratus
Is the app including the port number in redirects? If so, you can try rewriting the redirects using the HTTP profile option. Or you can use an iRule:when HTTP_RESPONSE { Check if response is a redirect if {[HTTP::is_redirect]}{ Replace :55555/ with / in the Location header HTTP::header replace Location [string map {:55555/ /} [HTTP::header value Location]] } }
- krelm_52303
Nimbostratus
Here's a version that is working for us (changing the Request Host header and URI), but hoping there's an easier way to modify the URI? - hoolio
Cirrostratus
Can you post some anonymized samples of the URI's you want to rewrite? Is the client using an absolute URI? Something like this?
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects