fix: vmagent not follow 301/302 redirect bug (#445)

Co-authored-by: xiaobeibei <xiaobeibei@bigo.sg>
This commit is contained in:
肖贝贝 2020-04-28 06:29:37 +08:00 committed by Aliaksandr Valialkin
parent 424068f804
commit 3e6f29f462

View File

@ -133,6 +133,15 @@ var (
func doRequestWithPossibleRetry(hc *fasthttp.HostClient, req *fasthttp.Request, resp *fasthttp.Response) error {
// There is no need in calling DoTimeout, since the timeout must be already set in hc.ReadTimeout.
err := hc.Do(req, resp)
if err == nil && (resp.Header.StatusCode() == 301 || resp.Header.StatusCode() == 302) {
l := string(resp.Header.Peek("Location"))
if l != "" {
req.URI().Update(l)
// only redirect once
err = hc.Do(req, resp)
}
}
if err == nil {
return nil
}