aboutsummaryrefslogtreecommitdiff
path: root/http.go
diff options
context:
space:
mode:
authorGravatar zzzzwc <94814774+zzzzwc@users.noreply.github.com> 2022-04-09 00:56:18 +0800
committerGravatar GitHub <noreply@github.com> 2022-04-08 18:56:18 +0200
commitf0e1be5665b560df1f37a1e491a8b0fffd57f689 (patch)
tree81f874eaa4aaf9ecb8c8d4436cd5f822bd08c7c0 /http.go
parentUse %v for errors and %q for strings (#1262) (diff)
downloadfasthttp-f0e1be5665b560df1f37a1e491a8b0fffd57f689.tar.gz
fasthttp-f0e1be5665b560df1f37a1e491a8b0fffd57f689.tar.bz2
fasthttp-f0e1be5665b560df1f37a1e491a8b0fffd57f689.zip
add nil check of req.body and resp.body on ReleaseBody (#1266)
Diffstat (limited to 'http.go')
-rw-r--r--http.go8
1 files changed, 7 insertions, 1 deletions
diff --git a/http.go b/http.go
index 4771db0..e8f9ec1 100644
--- a/http.go
+++ b/http.go
@@ -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)
@@ -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
@@ -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