Forum Discussion
Dan_Markhasin_1
Nimbostratus
Dec 01, 2015Capture all HTTP response headers
Hi,
Is there a way to capture all of the headers of the HTTP response? I am looking for something similar to HTTP::request which returns the raw HTTP headers of the request.
However, this c...
VernonWells
Employee
Dec 02, 2015Irritatingly, the DevCentral editor won't allow me to change what I have above, so here is a modified version that actually, you know, works:
ltm rule get-response-headers {
when RULE_INIT {
there is no built-in for multi character splits in Tcl. A common
trick is to map the split character token sets to a character that
cannot appear in the "real" data, then split on that single character.
Headers cannot contain the null, so we use that. Set this once because
it is (potentially) repeatedly used in a single connection pass
set static::http_header_multichar_split_map [list "\r\n" "\x00"]
}
when SERVER_CONNECTED {
set rhlist [list]
set hbuf ""
TCP::collect
}
when SERVER_DATA {
append hbuf [TCP::payload]
set hdone 0
if { $hbuf contains "\r\n\r\n" } {
Only process up to the \r\n\r\n. Ignore everything after
set hbuf [string range $hbuf 0 [expr { [string first "\r\n\r\n" $hbuf] - 1 }]]
set hdone 1
}
set rhlist [concat $rhlist [split [string map $static::http_header_multichar_split_map $hbuf] "\x00"]]
if { !$hdone } {
remove from the rolling buffer whatever was just processed
set hbuf [string range $hbuf [expr { [string last "\r\n" $hbuf] + 2 }] end]
}
TCP::release
if { $hdone } {
Remove the start line (e.g., HTTP/1.1 200 OK)
set rhlist [lreplace $rhlist 0 1]
log local0. " --> Have headers: [llength $rhlist] <--"
foreach hh $rhlist {
log local0. "$hh"
}
}
else {
TCP::collect
}
}
}
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