From 792860db10cec129d7cc036c417b3b9a81cc4a59 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Thu, 6 Jul 2023 10:31:35 -0700 Subject: [PATCH] lib/promscrape/discoveryutils: re-use checkRedirect function for both client and blockingClient Also document follow_redirects option at https://docs.victoriametrics.com/sd_configs.html#http-api-client-options This is a follow-up for b3d0ff463a7539496077b5844953c45e8942254f Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4282 --- docs/sd_configs.md | 4 ++++ lib/promscrape/discoveryutils/client.go | 7 +++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/sd_configs.md b/docs/sd_configs.md index 12b81c6b0..a5b9fa25d 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 eaeb57066..e5a51dcd6 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 {