Skip to content

Commit

Permalink
one more
Browse files Browse the repository at this point in the history
Signed-off-by: Sarah Funkhouser <[email protected]>
  • Loading branch information
golanglemonade committed Sep 4, 2024
1 parent 8661a56 commit 5b7ad88
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,27 +177,24 @@ func ConstantBackoffWithJitter(delay time.Duration) *ExponentialBackoff {
// Retry retries the http request under certain conditions - the number of retries,
// retry conditions, and the time to sleep between retries can be configured
func Retry(config *RetryConfig) Middleware {
var c RetryConfig

if config == nil {
c = DefaultRetryConfig
} else {
c := DefaultRetryConfig
if config != nil {
c = *config
}

c.normalize()

return func(next Doer) Doer {
return DoerFunc(func(req *http.Request) (*http.Response, error) {
if req.Body != nil && req.Body != http.NoBody && req.GetBody == nil {
if bodyEmpty(req) {
return next.Do(req)
}

var resp *http.Response

var err error

var attempt int
var (
resp *http.Response
err error
attempt int
)

for {
resp, err = next.Do(req)
Expand Down Expand Up @@ -232,6 +229,10 @@ func Retry(config *RetryConfig) Middleware {
}
}

func bodyEmpty(req *http.Request) bool {
return req.Body != nil && req.Body != http.NoBody && req.GetBody == nil
}

type errCloser struct {
io.Reader
err error
Expand Down

0 comments on commit 5b7ad88

Please sign in to comment.