Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read the response body inside the Backoff function (I think) #215

Open
paprikati opened this issue Mar 4, 2024 · 0 comments
Open

Comments

@paprikati
Copy link

paprikati commented Mar 4, 2024

From my testing, if you try to read the response body in the Backoff function, you get an error:

http2: response body closed

Is there any way to access the response body within that function? (In our case, the 'retry after' information is in the body of the response)

The code I'm testing is:

func newClient() http.Client {
	retryClient := retryablehttp.NewClient()
	retryClient.RetryMax = 3
	retryClient.Backoff = LisaTest
        return retryClient
}

func TestBackoff(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration {
	if resp != nil {
		var target map[string]interface{}
		err := json.NewDecoder(resp.Body).Decode(&target)
		spew.Dump(err)
		spew.Dump(target)
	}
	return 1 * time.Second
}

I could well be being thick here - would love to know if we're missing something simple (or it's some part of our implementation that I've missed)!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant