fix `ctx.SendStream(io.Reader)` huge memory usage (#2091)

* Update ctx.go

* remove content-length from test
pull/2095/head
Trim21 2022-09-15 13:19:25 +08:00 committed by GitHub
parent 8ec62a64cc
commit 709c52301c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 0 additions and 6 deletions

1
ctx.go
View File

@ -1545,7 +1545,6 @@ func (c *Ctx) SendStream(stream io.Reader, size ...int) error {
c.fasthttp.Response.SetBodyStream(stream, size[0])
} else {
c.fasthttp.Response.SetBodyStream(stream, -1)
c.setCanonical(HeaderContentLength, strconv.Itoa(len(c.fasthttp.Response.Body())))
}
return nil

View File

@ -3302,11 +3302,6 @@ func Test_Ctx_SendStream(t *testing.T) {
c.SendStream(bufio.NewReader(bytes.NewReader([]byte("Hello bufio"))))
utils.AssertEqual(t, "Hello bufio", string(c.Response().Body()))
file, err := os.Open("./.github/index.html")
utils.AssertEqual(t, nil, err)
c.SendStream(bufio.NewReader(file))
utils.AssertEqual(t, true, c.Response().Header.ContentLength() > 200)
}
// go test -run Test_Ctx_Set