Variable Scope with HTTP requests and collected data
I would like to be able to direct a request based on the content of some of the XML content in the request body. So far I have only ever done this in the HTTP_REQUEST event. In fact we have a basic framework that means all I need to do is set a variable "poolname" in the HTTP_REQUEST event and another irule will do all the error handling of non-existant pools or unavailable nodes etc and will deal with the request from there.
In this case I need to collect payload with HTTP::collect and I set a variable in the HTTP_REQUEST_DATA event. It appears this variable is not available after the HTTP:collect line in the HTTP_REQUEST event.
Is that expected?
e.g In the code below action will always be logged as unknown. If I put the log line in an HTTP_RESPONSE block it has been set correctly, so the code is working.
when HTTP_REQUEST {
set vhost [HTTP::host]:[TCP::local_port]
set action "unknown"
if {[HTTP::header "Content-Length"] ne "" && [HTTP::header "Content-Length"] <= 1048576}{
set req_length [HTTP::header "Content-Length"]
} else {
set req_length 1048576
}
if { $req_length > 0} {
HTTP::collect $req_length
}
log local0.info "Reqest $vhost with $action action\r\n"
}
WHEN HTTP_REQUEST_DATA {
if { $req_contenttype starts_with "text/xml" } {
set soapstart [ expr { [string first "" [HTTP::payload]] + 13 } ]
set soapend [expr {$soapstart + 20}]
set action [string range [HTTP::payload] $soapstart $soapend]
}
HTTP::release
}