|
|
@ -1,7 +1,6 @@
|
|
|
|
package http
|
|
|
|
package http
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
stdhttp "net/http"
|
|
|
|
stdhttp "net/http"
|
|
|
|
"net/url"
|
|
|
|
"net/url"
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -29,12 +28,13 @@ func (f *FollowRedirect) RoundTrip(req *stdhttp.Request) (*stdhttp.Response, err
|
|
|
|
|
|
|
|
|
|
|
|
if res.StatusCode >= 300 && res.StatusCode <= 399 {
|
|
|
|
if res.StatusCode >= 300 && res.StatusCode <= 399 {
|
|
|
|
loc := res.Header.Get("location")
|
|
|
|
loc := res.Header.Get("location")
|
|
|
|
|
|
|
|
|
|
|
|
fmt.Println("==> got a redirect, following...")
|
|
|
|
|
|
|
|
if loc != "" {
|
|
|
|
if loc != "" {
|
|
|
|
u, err := url.Parse(loc)
|
|
|
|
u, err := url.Parse(loc)
|
|
|
|
if err != nil {
|
|
|
|
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 := req.Clone(req.Context())
|
|
|
|
clone.URL = u
|
|
|
|
clone.URL = u
|
|
|
|