Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add nil check of req.body and resp.body on ReleaseBody #1266

Merged
merged 1 commit into from Apr 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion http.go
Expand Up @@ -261,7 +261,7 @@ func (resp *Response) IsBodyStream() bool {
//
// Note that GET and HEAD requests cannot have body.
//
/// See also SetBodyStream.
// See also SetBodyStream.
func (req *Request) SetBodyStreamWriter(sw StreamWriter) {
sr := NewStreamReader(sw)
req.SetBodyStream(sr, -1)
Expand Down Expand Up @@ -582,6 +582,9 @@ func (req *Request) SetBodyRaw(body []byte) {
// The majority of workloads don't need this method.
func (resp *Response) ReleaseBody(size int) {
resp.bodyRaw = nil
if resp.body == nil {
return
}
if cap(resp.body.B) > size {
resp.closeBodyStream() //nolint:errcheck
resp.body = nil
Expand All @@ -597,6 +600,9 @@ func (resp *Response) ReleaseBody(size int) {
// The majority of workloads don't need this method.
func (req *Request) ReleaseBody(size int) {
req.bodyRaw = nil
if req.body == nil {
return
}
if cap(req.body.B) > size {
req.closeBodyStream() //nolint:errcheck
req.body = nil
Expand Down