Kirk_Bauer_1018
Mar 31, 2007Nimbostratus
Can't get HTTP payload modification iRule to work
I have tried this rule, largely pieced together from sample code on this site:
when HTTP_REQUEST {
set uri [HTTP::uri]
}
when HTTP_RESPONSE {
log local0. "$uri: [HTTP::header Content-Type]"
Only check responses that are a text content type
(text/html, text/xml, text/plain, etc).
if { [HTTP::header "Content-Type"] starts_with "text/" } {
Get the content length so we can request the data to be
processed in the HTTP_RESPONSE_DATA event.
if { [HTTP::header exists "Content-Length"] } {
set content_length [HTTP::header "Content-Length"]
} else {
set content_length 4294967295
}
if { $content_length > 0 } {
log local0. "Collecting data"
HTTP::collect $content_length
}
}
}
when HTTP_RESPONSE_DATA {
log local0. "Entered HTTP_RESPONSE_DATA"
set indices [regexp -all -inline -indices {search_regex} [HTTP::payload]]
foreach idx $indices {
set start [lindex $idx 0]
set end [lindex $idx 1]
set len [expr {$end - $start + 1}]
log local0. "Found String, len=$len"
HTTP::payload replace $start $len "replace_string"
}
}
Where "search_regex" is my actual search regex taken out here for simplicity. The page in question is very short and does NOT have a content-length header. I consistently have unexpected behavior with this rule.
1) After saving the rule, the first page load will hang. I'm guessing because we are trying to collect more data than exists -- possibly because the entire page fits in the first response packet? When I look in the log I see "Collecting Data" as the last log line.
2) When I reload the page in my browser, that causes the log entries "Entered HTTP_RESPONSE_DATA" followed by "Found String, len=34". Then it is immediately followed by a log entry for the new page request, but it never hits the "collecting data" message again. In fact from now on I can reload the page fine (no more hanging) but it never collects data and never changes the page.
I need to search for a regex so unfortunately stream profile will not work. I hope I'm missing something stupid here?
Thanks!