Skip to content

Commit

Permalink
Fix bug for close connection response with no body.
Browse files Browse the repository at this point in the history
cow should add content-length: 0 header to indicate the end of close
connection responses with no body, add chunked encoding for those has body.

Safari will wait for body when cow incorrectly adds the chunked header.
As Safari limits number of concurrent connections to the proxy, it will
block on such erroneous responses.
  • Loading branch information
cyfdecyf committed Jul 28, 2013
1 parent 33d5c05 commit 0cf8188
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion http.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,8 +602,20 @@ func parseResponse(sv *serverConn, r *Request, rp *Response) (err error) {
// Connection close, no content length specification
// Use chunked encoding to pass content back to client
if !rp.ConnectionKeepAlive && !rp.Chunking && rp.ContLen == -1 {
rp.raw.WriteString("Transfer-Encoding: chunked\r\n")
if rp.hasBody(r.Method) {
debug.Println("add chunked encoding to close connection response", r, rp)
rp.raw.WriteString("Transfer-Encoding: chunked\r\n")
} else {
debug.Println("add content-length 0 to close connection response", r, rp)
rp.raw.WriteString("Content-Length: 0\r\n")
}
}
// Check for invalid response
if !rp.hasBody(r.Method) && (rp.Chunking || rp.ContLen != -1) {
errl.Printf("response has no body, but with chunked/content-length set\n%s",
rp.Verbose())
}

// Whether COW should respond with keep-alive depends on client request,
// not server response.
if r.ConnectionKeepAlive {
Expand Down

0 comments on commit 0cf8188

Please sign in to comment.