Mike_Sullivan_2
Dec 10, 2014Nimbostratus
Solved
iRule using TCP::collect and TCP::payload to fix blanks (spaces) in HTTP request
Hi
I have a request to help fix mal-formed links. After some research, it looks like an irule around the CLIENT_ACCEPTED and CLIENT_DATA events utilizing the TCP commands is the way to fix it.
I wrote a rule that seems to "work", except that when it processes the request and has finished its job, the front end connection request times out. tcpdump on the backend shows that the sever side connection is never made. Below is the rule:
when CLIENT_ACCEPTED {
log local0. "-"
TCP::collect 200
}
when CLIENT_DATA {
log local0. "-"
if { [TCP::payload 28] contains "GET /?engine=google&s_kwcid=" } {
log local0. "Google Keyword Match"
set mymatch [findstr [TCP::payload] "GET" 0 "\r\n"]
set mybal [findstr [TCP::payload] "\r\n" 0]
set myfields [split $mymatch " "]
if { [llength $myfields] > 3 } {
log local0. "Found Blanks in Request"
set mynewreq [concat [lindex $myfields 0] [join [lrange $myfields 1 end-1] "+"] [lindex $myfields end]]
log local0. "Request Fixed : $mynewreq"
} else {
log local0. "No Blanks in Request"
set mynewreq $mymatch
}
TCP::payload replace 0 [TCP::payload length] ""
TCP::payload replace 0 0 [concat $mynewreq $mybal]
log local0. "TCP::payload -> [TCP::payload]"
TCP::release
TCP::collect
}
}
Any idea on why the sever side connection is not made?
Thanks, Mike
it seems \r\n\r\n is removed when using concat.
can you try this? it looks okay here.
TCP::payload replace 0 0 "[concat $mynewreq $mybal]\r\n\r\n"