Skip to content

Commit 1dade5b

Browse files
authored
sigv4: support nil body (#673)
Fixes #562 Fixes #465 Signed-off-by: Julien Pivotto <[email protected]>
1 parent 430dbfe commit 1dade5b

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

sigv4/sigv4.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,14 @@ func (rt *sigV4RoundTripper) RoundTrip(req *http.Request) (*http.Response, error
110110
buf.Reset()
111111
rt.pool.Put(buf)
112112
}()
113-
if _, err := io.Copy(buf, req.Body); err != nil {
114-
return nil, err
113+
114+
if req.Body != nil {
115+
if _, err := io.Copy(buf, req.Body); err != nil {
116+
return nil, err
117+
}
118+
// Close the original body since we don't need it anymore.
119+
_ = req.Body.Close()
115120
}
116-
// Close the original body since we don't need it anymore.
117-
_ = req.Body.Close()
118121

119122
// Ensure our seeker is back at the start of the buffer once we return.
120123
var seeker io.ReadSeeker = bytes.NewReader(buf.Bytes())

sigv4/sigv4_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,11 @@ func TestSigV4RoundTripper(t *testing.T) {
107107

108108
require.Equal(t, "/test/test", gotReq.URL.Path)
109109
})
110+
111+
t.Run("No body", func(t *testing.T) {
112+
req, err := http.NewRequest(http.MethodGet, "https://example.com/test/test", nil)
113+
require.NoError(t, err)
114+
_, err = cli.Do(req)
115+
require.NoError(t, err)
116+
})
110117
}

0 commit comments

Comments
 (0)