mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/promscrape: adds correct http status codes for redirect (#2530)
standard http client accepts multiple http status codes as redirect it should fix issue with incorrect redirects https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2482
This commit is contained in:
parent
b5fedfd3bb
commit
3575aabeaf
1 changed files with 10 additions and 1 deletions
|
@ -201,6 +201,15 @@ func (c *client) GetStreamReader() (*streamReader, error) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
// checks fasthttp status code for redirect as standard http/client does.
|
||||
func isStatusRedirect(statusCode int) bool {
|
||||
switch statusCode {
|
||||
case 301, 302, 303, 307, 308:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *client) ReadData(dst []byte) ([]byte, error) {
|
||||
deadline := time.Now().Add(c.hc.ReadTimeout)
|
||||
req := fasthttp.AcquireRequest()
|
||||
|
@ -237,7 +246,7 @@ func (c *client) ReadData(dst []byte) ([]byte, error) {
|
|||
err := doRequestWithPossibleRetry(c.hc, req, resp, deadline)
|
||||
statusCode := resp.StatusCode()
|
||||
redirectsCount := 0
|
||||
for err == nil && (statusCode == fasthttp.StatusMovedPermanently || statusCode == fasthttp.StatusFound) {
|
||||
for err == nil && isStatusRedirect(statusCode) {
|
||||
if redirectsCount > 5 {
|
||||
err = fmt.Errorf("too many redirects")
|
||||
break
|
||||
|
|
Loading…
Reference in a new issue