Req 0.5.15 does not handle relative :url paths.
URI.merge/2 is capable of constructing URLs from relative path segments. For example:
iex> base_url = "http://localhost:8999/api"
iex> merged = URI.merge(base_url, "../health") |> URI.to_string
"http://localhost:8999/health"
iex> Req.request!(merged) |> Map.get(:body) |> JSON.decode!
%{"status" => "OK"}
curl is capable of dealing with relative paths:
$ curl -s -w "\n" "http://localhost:8999/api/../health"
{"status":"OK"}
Meanwhile, doing this with Req fails:
iex> req = Req.new(base_url: base_url)
iex> {rq, rs} = req |> Req.run(url: "../health")
iex> rq
%Req.Request{
method: :get,
url: URI.parse("http://localhost:8999/api/../health"),
headers: %{"accept-encoding" => ["gzip"], "user-agent" => ["req/0.5.15"]},
...
}
iex> JSON.decode!(rs.body)
** (JSON.DecodeError) invalid byte 60 at position (byte offset) 0
(elixir 1.18.3) lib/json.ex:339: JSON.decode!/1
iex:10: (file)
Should the value of :url in the constructed %Req.Request{} struct when passing a relative-path value in :url not be the same that URI.merge(base_url, "../health") returns?
Req 0.5.15 does not handle relative
:urlpaths.URI.merge/2is capable of constructing URLs from relative path segments. For example:curlis capable of dealing with relative paths:Meanwhile, doing this with Req fails:
Should the value of
:urlin the constructed%Req.Request{}struct when passing a relative-path value in:urlnot be the same thatURI.merge(base_url, "../health")returns?