diff --git a/http/round_tripper.go b/http/round_tripper.go index 7845af2..4630f26 100644 --- a/http/round_tripper.go +++ b/http/round_tripper.go @@ -1,7 +1,6 @@ package http import ( - "fmt" stdhttp "net/http" "net/url" ) @@ -29,12 +28,13 @@ func (f *FollowRedirect) RoundTrip(req *stdhttp.Request) (*stdhttp.Response, err if res.StatusCode >= 300 && res.StatusCode <= 399 { loc := res.Header.Get("location") - - fmt.Println("==> got a redirect, following...") if loc != "" { u, err := url.Parse(loc) if err != nil { - panic("got an invalid URL from the `location` header") + // If the location header can't be parsed as a URL, exit early + // and return the original response without attempting to follow + // the redirect. + return res, nil } clone := req.Clone(req.Context()) clone.URL = u