diff --git a/docs/sd_configs.md b/docs/sd_configs.md index 12b81c6b04..a5b9fa25da 100644 --- a/docs/sd_configs.md +++ b/docs/sd_configs.md @@ -1607,4 +1607,8 @@ and in the majority of [supported service discovery configs](#supported-service- # proxy_headers: # - "HeaderName1: HeaderValue" # - "HeaderNameN: HeaderValueN" + + # follow_redirects can be used for disallowing HTTP redirects. + # By default HTTP redirects are followed. + # follow_redirects: false ``` diff --git a/lib/promscrape/discoveryutils/client.go b/lib/promscrape/discoveryutils/client.go index eaeb570664..e5a51dcd6d 100644 --- a/lib/promscrape/discoveryutils/client.go +++ b/lib/promscrape/discoveryutils/client.go @@ -143,12 +143,11 @@ func NewClient(apiServer string, ac *promauth.Config, proxyURL *proxy.URL, proxy } } if httpCfg.FollowRedirects != nil && !*httpCfg.FollowRedirects { - client.CheckRedirect = func(req *http.Request, via []*http.Request) error { - return http.ErrUseLastResponse - } - blockingClient.CheckRedirect = func(req *http.Request, via []*http.Request) error { + checkRedirect := func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse } + client.CheckRedirect = checkRedirect + blockingClient.CheckRedirect = checkRedirect } setHTTPProxyHeaders := func(req *http.Request) {} if proxyAC != nil {