From 4eb68b53362ba52cf91a6a6e90cf24b539361d4b Mon Sep 17 00:00:00 2001 From: Derrick Zhang Date: Wed, 30 Aug 2023 01:01:28 -0500 Subject: [PATCH] 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 --- lib/http_client_builder.ex | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/http_client_builder.ex b/lib/http_client_builder.ex index 150c303..a025788 100755 --- a/lib/http_client_builder.ex +++ b/lib/http_client_builder.ex @@ -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 @@ -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