add SetRedirectLimit function to client

This commit is contained in:
wnstar
2020-06-21 19:17:39 +08:00
parent 2c0cfa24b0
commit ab8fbf171e

View File

@ -147,3 +147,14 @@ func (c *Client) SetRetry(retryCount int, retryInterval time.Duration) *Client {
c.retryInterval = retryInterval
return c
}
// SetRedirectLimit limit the number of jumps
func (c *Client) SetRedirectLimit(redirectLimit int) *Client {
c.CheckRedirect = func(req *http.Request, via []*http.Request) error {
if len(via) >= redirectLimit {
return http.ErrUseLastResponse
}
return nil
}
return c
}