Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
elixir 1.13.0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intention here is to support versions as early as possible, to keep the library compatible with as many versions of Elixir and OTP as possible. I'll add a comment to that effect.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

erlang 24.0.1
elixir 1.18.2
erlang 27.3.1
11 changes: 10 additions & 1 deletion lib/reverse_proxy_plug/http_client/adapters/req.ex
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,16 @@ if Code.ensure_loaded?(Req) do
end

defp normalize_headers(headers) do
Enum.map(headers, fn {k, v} -> {k, v |> List.wrap() |> Enum.join(", ")} end)
Enum.flat_map(headers, fn
{"set-cookie", values} when is_list(values) ->
Enum.map(values, &{"set-cookie", &1})

{"set-cookie", value} ->
[{"set-cookie", value}]

{k, v} ->
[{k, v |> List.wrap() |> Enum.join(", ")}]
end)
end
end
end
38 changes: 38 additions & 0 deletions test/http_client/adapters/req_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,44 @@ defmodule ReverseProxyPlug.HTTPClient.Adapters.ReqTest do

assert {:error, %Error{reason: :econnrefused}} == ReqClient.request(req)
end

test "should not merge set-cookie headers with method #{method}", %{bypass: bypass} do
path = "/my-resource"

req = %Request{
method: unquote(method),
options: [finch: FinchTest],
url: "http://localhost:8000#{path}"
}

Bypass.expect_once(bypass, fn %Plug.Conn{} = conn ->
assert conn.method == req.method |> to_string() |> String.upcase()
assert conn.request_path == path

conn
|> Plug.Conn.prepend_resp_headers([{"set-cookie", "foo=bar; Path=/"}])
|> Plug.Conn.prepend_resp_headers([{"set-cookie", "baz=quux; Path=/"}])
|> Plug.Conn.send_resp(204, "")
end)

assert {:ok, stream} = ReqClient.request_stream(req)

assert [
{:status, 204},
{:headers, headers}
] = Enum.to_list(stream)

set_cookie_headers =
Enum.filter(headers, fn
{"set-cookie", _} -> true
_ -> false
end)

assert set_cookie_headers == [
{"set-cookie", "foo=bar; Path=/"},
{"set-cookie", "baz=quux; Path=/"}
]
end
end
end
end