Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
package digest

import (
"bytes"
"crypto/md5"
"crypto/rand"
"crypto/sha256"
Expand Down Expand Up @@ -308,18 +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.
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))

// 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 {
Expand Down