cleanup follow redirect middleware

otelq
William Perron 2 years ago
parent 6b6ecff1fd
commit 4cc9309374
No known key found for this signature in database
GPG Key ID: D1815C43C9BA3DE1

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

Loading…
Cancel
Save