From 4cc9309374a047d27d38e25ff9288d453c2e0b27 Mon Sep 17 00:00:00 2001 From: William Perron Date: Thu, 16 Feb 2023 14:20:58 -0500 Subject: [PATCH] cleanup follow redirect middleware --- http/round_tripper.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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