Skip to content

Does not handle relative :url paths, even though URI.merge/2 does #505

@waseigo

Description

@waseigo

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions