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

response body is compressed in the retry function I provided #413

Open
stefanluptak opened this issue Sep 20, 2024 · 2 comments
Open

response body is compressed in the retry function I provided #413

stefanluptak opened this issue Sep 20, 2024 · 2 comments

Comments

@stefanluptak
Copy link
Contributor

I am doing this

Req.request(base_request(), url: "some url", method: :get)

defp base_request do
  Req.new(retry: &maybe_retry/2, retry_delay: &retry_delay/1, max_retries: 10)
end

and inside my maybe_retry/2 function, when I try to access the response.body, the content is compressed.

After I do this below, it works.

defp maybe_retry(request, %Req.Response{status: 403} = response) do
  {_request, %Req.Response{body: decompressed_body}} = Req.Steps.decompress_body({request, response})

  decoded_body = Jason.decode!(decompressed_body)

  match?(%{"message" => "You have exceeded a secondary rate limit" <> _}, decoded_body)
end

I assumed that the body will be already decompressed as it is in the result of the Req.new() call. Am I mistaken or is this a bug?

@wojtekmach
Copy link
Owner

The reason it works like this is retry is the very first response step, https://github.com/wojtekmach/req/blob/v0.5.6/lib/req/steps.ex#L85, so it happens before we decompress and decode. I'll need to think some more if we can change the order.

@stefanluptak
Copy link
Contributor Author

I think just mentioning this in the docs could be enough.

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

2 participants