From 2fd89f7c41e38863d75d483931a4a9ae8e3915b5 Mon Sep 17 00:00:00 2001 From: Andy Janata Date: Wed, 8 Mar 2023 14:28:20 -0800 Subject: [PATCH] check for http.NoBody as well as nil Body --- rehttp.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rehttp.go b/rehttp.go index 0879e5d..44f0e48 100644 --- a/rehttp.go +++ b/rehttp.go @@ -282,7 +282,7 @@ 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. @@ -290,7 +290,7 @@ func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) { // 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