mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-14 15:56:44 +03:00
Fixed transfer-encoding for empty chunked payload (#1536)
This commit is contained in:
@@ -1268,7 +1268,7 @@ func (req *Request) ContinueReadBody(r *bufio.Reader, maxBodySize int, preParseM
|
||||
return err
|
||||
}
|
||||
|
||||
if req.Header.ContentLength() == -1 {
|
||||
if contentLength == -1 {
|
||||
err = req.Header.ReadTrailer(r)
|
||||
if err != nil && err != io.EOF {
|
||||
return err
|
||||
@@ -1290,6 +1290,9 @@ func (req *Request) ReadBody(r *bufio.Reader, contentLength int, maxBodySize int
|
||||
|
||||
} else if contentLength == -1 {
|
||||
bodyBuf.B, err = readBodyChunked(r, maxBodySize, bodyBuf.B)
|
||||
if err == nil && len(bodyBuf.B) == 0 {
|
||||
req.Header.SetContentLength(0)
|
||||
}
|
||||
|
||||
} else {
|
||||
bodyBuf.B, err = readBodyIdentity(r, maxBodySize, bodyBuf.B)
|
||||
|
||||
@@ -2011,6 +2011,25 @@ func TestRequestReadChunked(t *testing.T) {
|
||||
verifyTrailer(t, rb, map[string]string{"Trail": "test"}, true)
|
||||
}
|
||||
|
||||
func TestRequestChunkedEmpty(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var req Request
|
||||
|
||||
s := "POST /foo HTTP/1.1\r\nHost: google.com\r\nTransfer-Encoding: chunked\r\nContent-Type: aa/bb\r\n\r\n0\r\n\r\n"
|
||||
r := bytes.NewBufferString(s)
|
||||
rb := bufio.NewReader(r)
|
||||
err := req.Read(rb)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error when reading chunked request: %v", err)
|
||||
}
|
||||
expectedBody := ""
|
||||
if string(req.Body()) != expectedBody {
|
||||
t.Fatalf("Unexpected body %q. Expected %q", req.Body(), expectedBody)
|
||||
}
|
||||
expectRequestHeaderGet(t, &req.Header, HeaderTransferEncoding, "")
|
||||
}
|
||||
|
||||
// See: https://github.com/erikdubbelboer/fasthttp/issues/34
|
||||
func TestRequestChunkedWhitespace(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
Reference in New Issue
Block a user