ltm rule command HTTP request
iRule(1) BIG-IP TMSH Manual iRule(1)
HTTP::request
Returns the raw HTTP request headers as a string.
SYNOPSIS
HTTP::request
DESCRIPTION
Returns the raw HTTP request headers as a string.
RETURN VALUE
Returns the raw HTTP request headers as a string. You can access the
request payload (e.g. POST data) by triggering payload collection with
the [HTTP::collect] command and then using [HTTP::payload] in the
[HTTP_REQUEST_DATA] event.
VALID DURING
HTTP_REQUEST HTTP_PROXY_REQUEST
EXAMPLES
# Note: this example would not work if the client sends a POST request with a payload, as HTTP::request does not return the payload.
when HTTP_REQUEST {
# Exit this event if the request isn't a GET
if {[HTTP::method] ne "GET"}{return}
# save original request headers
set req [HTTP::request]
# flag as new request needing lookup
set lookup 1
# inject lookup URI in place of original request
HTTP::uri "/page.aspx?ip=[IP::client_addr]"
# set pool to lookup server pool
pool lookup_server
}
when HTTP_RESPONSE {
if {$lookup == 1 }{
# collect first response (from lookup server) only
HTTP::collect 1
}
}
when HTTP_RESPONSE_DATA {
# Get poolname from server response
# Response would ideally be in the form of a pool name only.
# Otherwise parse or derive the poolname here
set myPool [HTTP::payload]
# re-set flag so that subsequent response to re-tried
# request from real server is not processed as a lookup
set lookup 0
# verify pool exists and has members
if { ![catch [pool $myPool]] }{
# Retry the request with the request headers set
HTTP::retry $req
} else {
#
# insert dead/non-existent pool logic here
#
}
}
And another one:
when HTTP_REQUEST {
# llength uses the spaces as well as carriage returns and line feeds
log local0. "list length: [llength [HTTP::request]], all headers: [HTTP::request]"
# Log the request headers in hex
binary scan [HTTP::request] H* request_hex
log local0. "hex: $request_hex"
# Replace the main whitespace characters with their hex equivalent (ie, " " -> \x20)
log local0. "escaped: [string map {\x20 \\x20 \x0d \\x0d \x0a \\x0a} [HTTP::request]]"
# Use string map to remove the \x0d carriage return
# then split the string on the \x0a linefeeds into a list
set headers [split [string map {\x0d ""} [HTTP::request]] \x0a]
set len [llength $headers]
# Loop through each request header line and log it
for { set i 0 } { $i < $len } { incr i } {
log local0. "$i = [lindex $headers $i]"
}
}
# /var/log/ltm output:
: list length: 9, all headers: GET /test.html HTTP/1.1 User-Agent: curl/7.41.0 Host: 11.3.0.10
: hex: 474554202f746573742e68746d6c20485454502f312e310d0a557365722d4167656e743a206375726c2f372e34312e300d0a486f73743a2031312e332e302e31300d0a4163636570743a202a2f2a0d0a0d0a
: escaped: GET\x20/test.html\x20HTTP/1.1\x0d\x0aUser-Agent:\x20curl/7.41.0\x0d\x0aHost:\x2011.3.0.10\x0d\x0a\x0d\x0a\x0d\x0a
: 0 = GET /test.html HTTP/1.1
: 1 = User-Agent: curl/7.41.0
: 2 = Host: 11.3.0.10
: 3 =
: 4 =
: 5 =
HINTS
SEE ALSO
CHANGE LOG
@BIGIP-9.2.0 --First introduced the command.
BIG-IP 2017-01-31 iRule(1)