From ab8fbf171e76c7787e42a4c4c80f1e6d854b516e Mon Sep 17 00:00:00 2001 From: wnstar <329291362@qq.com> Date: Sun, 21 Jun 2020 19:17:39 +0800 Subject: [PATCH] add SetRedirectLimit function to client --- net/ghttp/ghttp_client_config.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/net/ghttp/ghttp_client_config.go b/net/ghttp/ghttp_client_config.go index 49c00ee46..7d94ed3bc 100644 --- a/net/ghttp/ghttp_client_config.go +++ b/net/ghttp/ghttp_client_config.go @@ -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 +}