hashicorp / go-retryablehttp

Retryable HTTP client in Go
Mozilla Public License 2.0
1.99k stars 251 forks source link

using this client with RP #172

Closed mh-cbon closed 2 years ago

mh-cbon commented 2 years ago

Hey,

for retry purposes I mixed that client with httputil.NewSingleHostReverseProxy, like in

retryClient := retryablehttp.NewClient()
proxy := httputil.NewSingleHostReverseProxy(component.Target)
proxy.Transport = &retryablehttp.RoundTripper{
    Client: retryClient,
}

I had to deal with two difficulties.

The retryablehttp.Client.RequestLogHook must be set to get rid of RequestURI, otherwise the client hits the error http: Request.RequestURI can't be set in client requests.

retryClient.RequestLogHook = func(l retryablehttp.Logger, r *http.Request, n int) {
    r.RequestURI = ""
}

the retryablehttp.Client.HTTPClient.CheckRedirect must be set to not follow redirects, otherwise they are not passed straight to the other end of the wire and stuff, like cookies, might end up lost.

retryClient.HTTPClient.CheckRedirect = func(req *http.Request, via []*http.Request) error {
   return http.ErrUseLastResponse
}

Tha's all, maybe someone else did that before and can provide some more hints.

Anyways, thanks !