From 5bd41250cae9f0f822bd0edf9fc06ecf2e8e5b96 Mon Sep 17 00:00:00 2001 From: XuHaoJun Date: Thu, 19 Aug 2021 10:12:39 +0800 Subject: [PATCH] fix: should drain resp.Body if not readAll or dump refs: https://pkg.go.dev/net/http#Client.Do https://forum.golangbridge.org/t/do-i-need-to-read-the-body-before-close-it/5594 https://github.com/google/go-github/pull/317 --- soap.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/soap.go b/soap.go index 9535ff3..489360d 100644 --- a/soap.go +++ b/soap.go @@ -5,6 +5,7 @@ import ( "encoding/xml" "errors" "fmt" + "io" "io/ioutil" "net/http" "net/http/httputil" @@ -261,6 +262,12 @@ func (p *process) doRequest(url string) ([]byte, error) { } if resp.StatusCode < 200 || resp.StatusCode >= 400 { + if !(p.Client.config != nil && p.Client.config.Dump) { + _, err := io.Copy(ioutil.Discard, resp.Body) + if err != nil { + return nil, err + } + } return nil, errors.New("unexpected status code: " + resp.Status) }