Skip to content

Commit

Permalink
Remove duplicates from the combined header list of the runtime header…
Browse files Browse the repository at this point in the history
…s and compile time headers (#2)

* Remove duplicates from the combined header list of the runtime headers and compile time headers

* Feedback changes
  • Loading branch information
zillou authored Aug 30, 2023
1 parent 63d0e77 commit 4eb68b5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/http_client_builder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ defmodule HttpClientBuilder do

headers =
if unquote(client_opts)[:runtime_headers_getter] do
unquote(client_opts)[:runtime_headers_getter].() ++ compile_time_headers
(unquote(client_opts)[:runtime_headers_getter].() ++ compile_time_headers)
|> dedup_headers()
else
compile_time_headers
end
Expand All @@ -114,6 +115,12 @@ defmodule HttpClientBuilder do
base_url <> url_or_path <> query
end

defp dedup_headers(headers) do
headers
|> Enum.reduce(%{}, fn {k, v}, acc -> Map.put(acc, k, v) end)
|> Map.to_list()
end

defoverridable get: 2, post: 2, put: 2, delete: 2, patch: 2, do_request: 3, build_url: 2
end
end
Expand Down

0 comments on commit 4eb68b5

Please sign in to comment.