From f6173c2ca54979ff6ae495dae3ccd0134d6749f7 Mon Sep 17 00:00:00 2001 From: Jon Williams Date: Fri, 30 Apr 2021 17:22:30 -0400 Subject: [PATCH 1/2] on the first request, avoid posting body --- digest.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/digest.go b/digest.go index 4f16bf6..09654da 100644 --- a/digest.go +++ b/digest.go @@ -72,7 +72,6 @@ package digest import ( - "bytes" "crypto/md5" "crypto/rand" "crypto/sha256" @@ -312,13 +311,10 @@ func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) { // to obtain a fresh reader for the second request, which we do right // before the RoundTrip(origReq) call. If GetBody is unavailable, read // the body into a memory buffer and use it for both requests. - if req.Body != nil && req.GetBody == nil { - body, err := ioutil.ReadAll(req.Body) - if err != nil { - return nil, err - } - req.Body = ioutil.NopCloser(bytes.NewBuffer(body)) - origReq.Body = ioutil.NopCloser(bytes.NewBuffer(body)) + if req.Body != nil || req.GetBody == nil { + req.Body = nil + req.GetBody = nil + req.ContentLength = 0 } // Make a request to get the 401 that contains the challenge. challenge, resp, err := t.fetchChallenge(req) From c80f148c2b6194ae726a6e8b502e9a72c95d781a Mon Sep 17 00:00:00 2001 From: Jon Williams Date: Fri, 30 Apr 2021 17:35:27 -0400 Subject: [PATCH 2/2] try making a comment not lie --- digest.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/digest.go b/digest.go index 09654da..0b612a3 100644 --- a/digest.go +++ b/digest.go @@ -307,15 +307,14 @@ func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) { origReq.Header[k] = s } - // We'll need the request body twice. In some cases we can use GetBody - // to obtain a fresh reader for the second request, which we do right - // before the RoundTrip(origReq) call. If GetBody is unavailable, read - // the body into a memory buffer and use it for both requests. + + // Do not send the body on the first request if req.Body != nil || req.GetBody == nil { req.Body = nil req.GetBody = nil req.ContentLength = 0 } + // Make a request to get the 401 that contains the challenge. challenge, resp, err := t.fetchChallenge(req) if challenge == "" || err != nil {