Forum Discussion
hooleylist
Sep 16, 2009Cirrostratus
Hi,
There are a few issues. The first one that jumps out is you're using global variables where you should be using locals:
set ::InjectText 0
set ::uri ""
These should both be set as locals and removed from RULE_INIT:
set InjectText 0
set uri ""
Another potential issue is if the server response contains a Content-Length header set to a value greater than 4Mb TMM will crash.
SOL6578: TMM will crash if an iRule collects more than 4MB of data
https://support.f5.com/kb/en-us/solutions/public/6000/500/sol6578.html
You should consider logic like this to limit the payload collection size:
Trigger collection for up to 1MB of data
if {([HTTP::header exists "Content-Length"]) && ([HTTP::header "Content-Length"] <= 1024000)}{
set content_length [HTTP::header "Content-Length"]
} else {
set content_length 1024000
}
if { [info exists content_length] } {
HTTP::collect $content_length
if {$::rule_debug}{log local0. "[IP::client_addr]:[TCP::client_port]: Collecting $content_length"}
}
I didn't look too closely at the replacement logic. Does it work after you make the above changes?
In terms of optimisation, you could eliminate a lot of the intermediate variables like 'set ctype [HTTP::header Content-Type]' and just reference [HTTP::header Content-Type]. The value for most HTTP:: commands is cached in the same event so there isn't a performance hit for re-referencing the command. There is extra memory used when saving the values to a new variable though.
Aaron