req
req copied to clipboard
URI parameters appear to be duplicated on retry
Given this script:
Mix.install([
{:req, "0.3.1"}
])
require Logger
Req.new(url: "https://httpbin.org/status/408", params: [test: "a"])
|> Req.Request.append_request_steps(
log_request: fn request ->
Logger.debug("#{request.method} #{URI.to_string(request.url)}")
request
end
)
|> Req.get!()
… I get this output:
11:09:15.145 [debug] get https://httpbin.org/status/408?test=a
11:09:15.692 [error] retry: got response with status 408, will retry in 1000ms, 3 attempts left
11:09:16.694 [debug] get https://httpbin.org/status/408?test=a&test=a
11:09:16.778 [error] retry: got response with status 408, will retry in 2000ms, 2 attempts left
11:09:18.780 [debug] get https://httpbin.org/status/408?test=a&test=a&test=a
11:09:18.868 [error] retry: got response with status 408, will retry in 4000ms, 1 attempt left
11:09:22.871 [debug] get https://httpbin.org/status/408?test=a&test=a&test=a&test=a
Notice how on the first request, I have a single test=a
URI parameter, but on each subsequent attempt the URI parameters are duplicated.
Please let me know if I've done something wrongly here!
This is definitely a bug, thank you for reporting it. I think what is happening is the put_params/1 step merges the params into the URI but keeps the :params option around. And when we hit the error, the retry/1 step will take the request and run it again but now it has the url (with params applied) and the :params option, so it will append the params again. Don't know off the top of my head what's the best way to handle it, we need to either change put_params or retry or both.