ltm rule command URI port
iRule(1) BIG-IP TMSH Manual iRule(1)
URI::port
Returns the host port from the given URI.
SYNOPSIS
URI::port URI_STRING
DESCRIPTION
Returns the host port from the given URI.
Syntax
URI::port
* Returns the port from the given URI. Returns 80 by default for URIs
without a protocol or 0 if the protocol is unknown.
RETURN VALUE
Returns the host port from the given URI.
VALID DURING
ANY_EVENT
EXAMPLES
when HTTP_REQUEST {
set port [URI::port [HTTP::uri]]
log local0. "Host port of uri [HTTP::uri] is $port"
}
The default seems to be port 80 if a port isn't specified in the URI.
Here are a few tests (on 10.2.4):
when RULE_INIT {
# Loop through some test URLs and URIs and log the URI::port value
foreach uri [list \
http://example.com/file.ext \
http://example.com:80/file.ext \
https://example.com:443/file.ext \
https://example.com:8443/file.ext \
ftp://example.com/file.ext \
sip://example.com/file.ext \
myproto://example.com/file.ext \
/example.com \
/uri?url=http://example.com/uri \
] {
log local0. "\[URI::port $uri\]: [URI::port $uri]"
}
}
Log output
[URI::port http://example.com/file.ext]: 80
[URI::port http://example.com:80/file.ext]: 80
[URI::port https://example.com:443/file.ext]: 443
[URI::port https://example.com:8443/file.ext]: 8443
[URI::port ftp://example.com/file.ext]: 21
[URI::port sip://example.com/file.ext]: 5060
[URI::port myproto://example.com/file.ext]: 0
[URI::port /example.com]: 80
[URI::port /uri?url=http://example.com/uri]: 80
HINTS
SEE ALSO
CHANGE LOG
@BIGIP-9.0.0 --First introduced the command.
BIG-IP 2017-01-31 iRule(1)