diff --git a/digest.go b/digest.go index 89caa31..d2ee0e6 100644 --- a/digest.go +++ b/digest.go @@ -44,11 +44,13 @@ package digest import ( + "bytes" "crypto/md5" "crypto/rand" "errors" "fmt" "io" + "io/ioutil" "net/http" "strings" ) @@ -240,6 +242,15 @@ func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) { req2.Header[k] = s } + // Copy body - we need it twice. + if req.Body != nil { + body, err := ioutil.ReadAll(req.Body) + if err != nil { + return nil, err + } + req.Body = ioutil.NopCloser(bytes.NewBuffer(body)) + req2.Body = ioutil.NopCloser(bytes.NewBuffer(body)) + } // Make a request to get the 401 that contains the challenge. resp, err := t.Transport.RoundTrip(req) if err != nil || resp.StatusCode != 401 {