Skip to content

Commit

Permalink
Add RetryIfErr for Client
Browse files Browse the repository at this point in the history
Fix #1744
In PR 1818, we only add RetryIfErr for HostClient but not for Client.
  • Loading branch information
ksw2000 committed Aug 25, 2024
1 parent 25c52d7 commit 4f3f222
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,16 @@ type Client struct {
TLSConfig *tls.Config

// RetryIf controls whether a retry should be attempted after an error.
// By default, it uses the isIdempotent function.
//
// By default will use isIdempotent function.
// Deprecated: Use RetryIfErr instead.
// Panics if both RetryIf and RetryIfErr are set.
RetryIf RetryIfFunc

// RetryIfErr controls whether a retry should be attempted after an error.
// By default, it uses the isIdempotent function.
RetryIfErr RetryIfErrFunc

// ConfigureClient configures the fasthttp.HostClient.
ConfigureClient func(hc *HostClient) error

Expand Down Expand Up @@ -537,6 +543,7 @@ func (c *Client) Do(req *Request, resp *Response) error {
DisablePathNormalizing: c.DisablePathNormalizing,
MaxConnWaitTimeout: c.MaxConnWaitTimeout,
RetryIf: c.RetryIf,
RetryIfErr: c.RetryIfErr,
ConnPoolStrategy: c.ConnPoolStrategy,
StreamResponseBody: c.StreamResponseBody,
clientReaderPool: &c.readerPool,
Expand Down
2 changes: 1 addition & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2156,7 +2156,7 @@ func TestClientRetryRequestWithCustomDecider(t *testing.T) {
return nil, fmt.Errorf("unexpected number of dials: %d", dialsCount)
}
},
RetryIf: func(req *Request) bool {
RetryIfErr: func(req *Request, err error) bool {
return req.URI().String() == "http://foobar/a/b"
},
}
Expand Down

0 comments on commit 4f3f222

Please sign in to comment.