Forum Discussion
Capture all HTTP response headers
Ah, I understand now. The answer -- for better-or-worse 🙂 -- is no, there is no equivalent for HTTP Response headers. You could extract them in the SERVER_DATA event, but that performance is likely to be worse than iteration. Out of curiosity, what is the objective in having the headers? Logging? Or something else?
Oh, and just because I cannot resist a challenge, here is a possible iRule for raw Response header extraction:
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" } {
The header section terminates with \r\n\r\n but the body may also contain
this sequence. Ignore anything in the body.
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"]]
TCP::release
if { $hdone } {
set rhlist [lreplace $rhlist 0 1]
log local0. "Have headers: $rhlist"
}
else {
TCP::collect
}
}
}
I encourage you to test it, but as I said above, I suspect this is much less performant than iteration using the HTTP::header methods. And, well, it's probably super buggy, too :-p.
Recent Discussions
Related Content
* 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