Forum Discussion
Chip_Hudgins_64
Nimbostratus
Oct 26, 2005[HTTP::host] includes port
I have written an iRule that checks to make sure the host is a fully qualified domain name prior to processing the rest of the iRules for the virtual server.
This is the iRule:
when HTTP_REQUEST {
set DEBUG 0
set host "[HTTP::host]"
set port "[TCP::local_port]"
if {${port} == 443 } {
set protocol "https:"
} else {
set protocol "http:"
}
if { $DEBUG } {
log local0. "host is ${host}"
log local0. "port is ${port}"
log local0. "protocol is ${protocol}"
}
if { [ string length $host ] == 0 } {
set host [IP::local_addr]
if { $DEBUG } {
log local0. "Setting host to $host"
}
}
if { [string first "." ${host}] < 0 && [string length ${host}] >= 1} {
set host "[HTTP::host].domain.com
if { $DEBUG } {
log local0. "Redirect to FQDN - ${host}"
}
HTTP::redirect "${protocol}//${host}[ HTTP::uri ]"
return
}
}
This works well except when the port is not 80 or 443. For example, this above iRules returns the following for a request on port 8080
“Redirect to FQDN – foobar:8080.domain.com/whatever”
From the DEBUG logs, I see that [HTTP::host] returns both the hostname and the port when the port is not 80 or 443. For example, from log local0. "host is ${host}" returns host is foobar:8080.
Can anyone help with how I can strip the “port” out of the [HTTP::host] call and then I can re-add the port with
set port ""
if { [TCP::local_port] != 80 } {
set port ":[TCP::local_port]"
set host "[HTTP::host]${port}"
}
after I add the FQDN.
Thanks
- JRahm
Admin
set host_ip_and_port_list [ split [HTTP::host] ":" ] - Chip_Hudgins_64
Nimbostratus
Thanks! This is exactly what I needed.
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