Skip to content

Commit

Permalink
Merge pull request #5 from gametimesf/fix-no-body
Browse files Browse the repository at this point in the history
check for http.NoBody as well as nil Body
  • Loading branch information
mna authored Mar 9, 2023
2 parents 67bd845 + 2fd89f7 commit 075425b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions rehttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,15 +282,15 @@ type Transport struct {
// adds retry logic as per its configuration.
func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) {
var attempt int
preventRetry := req.Body != nil && t.PreventRetryWithBody
preventRetry := req.Body != nil && req.Body != http.NoBody && t.PreventRetryWithBody

// get the done cancellation channel for the context, will be nil
// for < go1.7.
done := contextForRequest(req)

// buffer the body if needed
var br *bytes.Reader
if req.Body != nil && !preventRetry {
if req.Body != nil && req.Body != http.NoBody && !preventRetry {
var buf bytes.Buffer
if _, err := io.Copy(&buf, req.Body); err != nil {
// cannot even try the first attempt, body has been consumed
Expand Down

0 comments on commit 075425b

Please sign in to comment.