Skip to content

Commit

Permalink
Ignore empty Transfer-Encoding headers
Browse files Browse the repository at this point in the history
Don't default to chunked. If we have a Content-Length header we have a fixed body.
  • Loading branch information
erikdubbelboer committed Jan 6, 2021
1 parent 6234776 commit 70e00dc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion header.go
Original file line number Diff line number Diff line change
Expand Up @@ -1839,7 +1839,7 @@ func (h *ResponseHeader) parseHeaders(buf []byte) (int, error) {
}
case 't':
if caseInsensitiveCompare(s.key, strTransferEncoding) {
if !bytes.Equal(s.value, strIdentity) {
if len(s.value) > 0 && !bytes.Equal(s.value, strIdentity) {
h.contentLength = -1
h.h = setArgBytes(h.h, strTransferEncoding, strChunked, argsHasValue)
}
Expand Down
16 changes: 16 additions & 0 deletions http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ import (
"github.com/valyala/bytebufferpool"
)

func TestResponseEmptyTransferEncoding(t *testing.T) {
t.Parallel()

var r Response

body := "Some body"
br := bufio.NewReader(bytes.NewBufferString("HTTP/1.1 200 OK\r\nContent-Type: aaa\r\nTransfer-Encoding: \r\nContent-Length: 9\r\n\r\n" + body))
err := r.Read(br)
if err != nil {
t.Fatal(err)
}
if got := string(r.Body()); got != body {
t.Fatalf("expected %q got %q", body, got)
}
}

// Don't send the fragment/hash/# part of a URL to the server.
func TestFragmentInURIRequest(t *testing.T) {
var req Request
Expand Down

0 comments on commit 70e00dc

Please sign in to comment.