Skip to content

Commit 03f63b5

Browse files
committed
fixed body empty
1 parent d3b455e commit 03f63b5

1 file changed

Lines changed: 10 additions & 13 deletions

File tree

httpsig.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"bytes"
99
"crypto/ecdsa"
1010
"crypto/rsa"
11-
"fmt"
1211
"io/ioutil"
1312
"net/http"
1413
"time"
@@ -60,20 +59,18 @@ func NewSignTransport(transport http.RoundTripper, opts ...signOption) http.Roun
6059
nr := r.Clone(r.Context())
6160

6261
b := &bytes.Buffer{}
63-
if r.Body != nil {
64-
n, err := b.ReadFrom(r.Body)
62+
if r.Body != nil {
63+
64+
// this broke the request
65+
// was getting net/http: HTTP/1.x transport connection broken: http: ContentLength=44 with Body length 0
66+
// switched to read bytes from a copy of body.
67+
bodyCopy, _ := r.GetBody()
68+
defer bodyCopy.Close()
69+
70+
_, err := b.ReadFrom(bodyCopy)
6571
if err != nil {
6672
return nil, err
67-
}
68-
69-
defer r.Body.Close()
70-
71-
if n != 0 {
72-
fmt.Println("body length", n)
73-
//TODO this breaks the request
74-
//net/http: HTTP/1.x transport connection broken: http: ContentLength=44 with Body length 0
75-
r.Body = ioutil.NopCloser(bytes.NewReader(b.Bytes()))
76-
}
73+
}
7774
}
7875

7976
// Always set a digest (for now)

0 commit comments

Comments
 (0)