Skip to content

Commit

Permalink
add nil check of req.body and resp.body on ReleaseBody (#1266)
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzzwc committed Apr 8, 2022
1 parent 7a5afdd commit f0e1be5
Showing 1 changed file with 7 additions and 1 deletion.
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

0 comments on commit f0e1be5

Please sign in to comment.