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:...
hoolio
Cirrostratus
Nov 20, 2008Hi there,
You can strip out anything after the : in the host header using the getfield command (Click here) or using scan in an iRule:
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]"
}
If the requests won't always have a port, you could check to see if the host header value contains a colon before replacing the value.
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]"
}
}
Here is an example using scan (Click here😞
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
}
}
I'm not sure whether scan would be more efficient than getfield. You could use the timing command to test this:
Timing command Click here, Timing article Click here
Aaron
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