Don't assume Content-Encoding: identity when request is 1xx, 204 or 304

This commit is contained in:
Sebastian Schepens
2016-01-12 15:23:14 -03:00
parent c8f577c7f1
commit fa88c5b853
2 changed files with 22 additions and 1 deletions
+1 -1
View File
@@ -1466,7 +1466,7 @@ func (h *ResponseHeader) parseHeaders(buf []byte) (int, error) {
if h.contentLength < 0 {
h.contentLengthBytes = h.contentLengthBytes[:0]
}
if h.contentLength == -2 && !h.ConnectionUpgrade() {
if h.contentLength == -2 && !h.ConnectionUpgrade() && !h.mustSkipContentLength() {
h.h = setArg(h.h, strTransferEncoding, strIdentity)
h.connectionClose = true
}
+21
View File
@@ -1032,6 +1032,27 @@ func TestResponseHeaderReadSuccess(t *testing.T) {
t.Fatalf("unexpected connection: close")
}
// no content-length (informational responses)
testResponseHeaderReadSuccess(t, h, "HTTP/1.1 101 OK\r\n\r\n",
101, -2, "text/plain; charset=utf-8", "")
if h.ConnectionClose() {
t.Fatalf("expecting connection: keep-alive for informational response")
}
// no content-length (no-content responses)
testResponseHeaderReadSuccess(t, h, "HTTP/1.1 204 OK\r\n\r\n",
204, -2, "text/plain; charset=utf-8", "")
if h.ConnectionClose() {
t.Fatalf("expecting connection: keep-alive for no-content response")
}
// no content-length (not-modified responses)
testResponseHeaderReadSuccess(t, h, "HTTP/1.1 304 OK\r\n\r\n",
304, -2, "text/plain; charset=utf-8", "")
if h.ConnectionClose() {
t.Fatalf("expecting connection: keep-alive for not-modified response")
}
// no content-length (identity transfer-encoding)
testResponseHeaderReadSuccess(t, h, "HTTP/1.1 200 OK\r\nContent-Type: foo/bar\r\n\r\nabcdefg",
200, -2, "foo/bar", "abcdefg")