You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I just noticed this as well -- I actually think that this is an error within the CheckRetry documentation as the originating caller of the request should still be able to introspect the body of their response (e.g. if they want to check some JSON object the server returns that gives more information on the error). So the Client closing the response body on retries makes sense, but for non-retry returns you should ideally NOT close the response body (and further, leave it in an unmodified state).
So, if you are looking to write some custom CheckRetry function that needs to introspect the response body, I believe something like this is the correct way to handle it --
client:=retryablehttp.NewClient()
client.CheckRetry=func(ctx context.Context, resp*http.Response, errerror) (bool, error) {
// ... -- initial checks/validationdeferresp.Body.Close()
body, rErr:=io.ReadAll(resp.Body)
ifrErr!=nil {
returnfalse, rErr
}
resp.Body=io.NopCloser(bytes.NewBuffer(body))
// ... -- using `body` to do w/e
}
I noticed in the docs for the CheckRetry function that its responsible for closing the response if the function determines retry should not be made:
go-retryablehttp/client.go
Lines 358 to 361 in 2bcd5fe
I went looking for an example of that in the default implementation but it looks like its not being done?
go-retryablehttp/client.go
Lines 462 to 486 in 2bcd5fe
Is this just an oversight?
thanks
The text was updated successfully, but these errors were encountered: