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 b3d0ff463a

Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4282
This commit is contained in:
Aliaksandr Valialkin 2023-07-06 10:31:35 -07:00
parent eb47ad4b69
commit 6a3cee5c2c
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1
2 changed files with 7 additions and 4 deletions

View file

@ -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
```

View file

@ -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 {