diff --git a/client.go b/client.go index 0a4e95c..9a98bcf 100644 --- a/client.go +++ b/client.go @@ -37,9 +37,6 @@ func New(client *http.Client, middlewares ...cliware.Middleware) *Client { if client == nil { client = http.DefaultClient } - if client.CheckRedirect == nil { - client.CheckRedirect = CopyHeadersRedirect - } retry.Enable(client) chain := cliware.NewChain(middlewares...) return &Client{ diff --git a/redirect.go b/redirect.go deleted file mode 100644 index c152d56..0000000 --- a/redirect.go +++ /dev/null @@ -1,33 +0,0 @@ -package gwc - -import ( - "errors" - "net/http" -) - -// CopyHeadersRedirect is CheckRedirect function that fixes issue -// github.com/golang/go/issues/4800. Namely, when redirect response is -// received, header from original request are not copied to new request. -// This function fixes that by copying all headers to new request except -// Authorization header (to avoid credentials leak). Authorization header -// is copied only if Host header from previous request matches with Host -// header of new request. -// This function implements same behaviour as standard lib does by default (error -// when more then 10 redirects happen), but it adds header copy feature. -func CopyHeadersRedirect(req *http.Request, via []*http.Request) error { - if len(via) >= 10 { - return errors.New("stopped after 10 redirects") - } - lastRequest := via[len(via)-1] - - for attr, val := range lastRequest.Header { - // if hosts do not match do not copy Authorization header - if attr == "Authorization" && req.Host != lastRequest.Host { - continue - } - if _, ok := req.Header[attr]; !ok { - req.Header[attr] = val - } - } - return nil -}