Skip to content

Commit 4eb68b5

Browse files
authored
Remove duplicates from the combined header list of the runtime headers and compile time headers (#2)
* Remove duplicates from the combined header list of the runtime headers and compile time headers * Feedback changes
1 parent 63d0e77 commit 4eb68b5

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lib/http_client_builder.ex

+8-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ defmodule HttpClientBuilder do
9696

9797
headers =
9898
if unquote(client_opts)[:runtime_headers_getter] do
99-
unquote(client_opts)[:runtime_headers_getter].() ++ compile_time_headers
99+
(unquote(client_opts)[:runtime_headers_getter].() ++ compile_time_headers)
100+
|> dedup_headers()
100101
else
101102
compile_time_headers
102103
end
@@ -114,6 +115,12 @@ defmodule HttpClientBuilder do
114115
base_url <> url_or_path <> query
115116
end
116117

118+
defp dedup_headers(headers) do
119+
headers
120+
|> Enum.reduce(%{}, fn {k, v}, acc -> Map.put(acc, k, v) end)
121+
|> Map.to_list()
122+
end
123+
117124
defoverridable get: 2, post: 2, put: 2, delete: 2, patch: 2, do_request: 3, build_url: 2
118125
end
119126
end

0 commit comments

Comments
 (0)