Forum Discussion

JCohen's avatar
JCohen
Icon for Employee rankEmployee
Feb 07, 2013

Invalid 304 response with content-length workaround

Based on some work in an old post I put together something that is working on a 10.x install. A bad backend server is sending 304 responses with a Content-Length and a body. I threw cobbled this together to cover that situation and thought I'd throw it up here in the event it helps someone else out.

 

Can't really figure out the formatting of this site, nor does the preview button work. Sorry for the ugliness...

 

when HTTP_REQUEST {

 

set request [HTTP::uri]

 

}

 

 

when HTTP_REQUEST_SEND {

 

set response_pending 1

 

set done 0

 

set response_304 0

 

set cl 0

 

SSL::collect 12

 

}

 

 

 

when SERVERSSL_DATA {

 

if {$response_pending == 1} {

 

Check for 304 response

 

if {[SSL::payload] starts_with "HTTP/1.1 304"} {

 

set response_304 1

 

set response_pending 0

 

} else {

 

SSL::release

 

return

 

}

 

}

 

if {$response_304 == 1} {

 

set index [string first "Content-Length" [SSL::payload]]

 

Check if header is found

 

if {$index != -1} {

 

log local0. "Invalid 304 response from [IP::server_addr]. Request was for: $request"

 

set colon [string first ":" [SSL::payload] $index]

 

set clend [string first "\r\n" [SSL::payload] $index]

 

if {$clend != -1} {

 

set cl [string trim [string range [SSL::payload] [expr $colon + 1] $clend ]]

 

SSL::payload replace $index 2 "X-"

 

}

 

}

 

set hdrend [string first "\r\n\r\n" [SSL::payload]]

 

if {$hdrend == -1} {

 

Dont have the end of header. Collect more.

 

SSL::collect

 

return

 

} else {

 

if {$cl == 0} {

 

SSL::release

 

return

 

} else {

 

set extra [string length [string range [SSL::payload] [expr $hdrend + 4] end]]

 

if {$extra == $cl} {

 

SSL::payload replace [expr $hdrend + 4] $cl ""

 

SSL::release

 

return

 

} else {

 

SSL::collect [expr $cl - $extra]

 

return

 

}

 

}

 

}

 

}

 

}