Well,
I've finally managed to get the thing to compile, but I'm not currently able to test it (because it's production traffic) but i guess it should work.
Here's the irule: where BadServers = foo.bar.com
when HTTP_REQUEST {
if { [matchclass [HTTP::host] equals $::BadServers] }{
set replace 1
}
}
when HTTP_RESPONSE {
if {$replace > 0}{
if {[HTTP::header exists "Content-Length"]}{
set clen [HTTP::header "Content-Length"]
} else {
set clen 4294967295
}
if { $clen > 0 } {
HTTP::collect $clen
}
}
}
when HTTP_RESPONSE_DATA {
if {$replace}{
find beginning of data to keep
set xml_start [string first { if { $xml_start > 0 }{
set newPayload [string range [HTTP::payload] $xml_start end]
HTTP::payload replace 0 $clen $newPayload
}
HTTP::release
Log Results
log local0. "Found $xml_start replaced with $newPayload"
}
}