Skip to content

Commit

Permalink
add base bitstring concat
Browse files Browse the repository at this point in the history
  • Loading branch information
geeksilva97 committed Apr 19, 2024
1 parent c6491b8 commit 9af49cd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
erlang 26.2.2
18 changes: 14 additions & 4 deletions src/cowboy_req.erl
Original file line number Diff line number Diff line change
Expand Up @@ -729,11 +729,21 @@ set_resp_header(Name,Value, Req) ->
% @todo process headers list - reduce to a map and concat the values of repeated headers, except for set-cookie that will be treated differently
% @todo define the correct spec
-spec set_resp_headers_list(list(term()), req())
set_resp_headers_list([], Req) ->
set_resp_headers_list(HeaderTupleList, Req) ->
set_resp_headers_list(HeaderTupleList, #{}, Req).

set_resp_headers_list([], Map, Req) ->
% @todo merge Map with Req headers
Req;
set_resp_headers_list([{Name, Value} | Headers], Req) ->
Req1 = set_resp_header(Name, Value, Req),
set_resp_headers_list(Headers, Req1).
set_resp_headers_list([{Name, Value} | Headers], Map, Req) ->
NewHeaderValue = case maps:get(Name, Map, undefined) of
undefined -> Value,
ExistingValue -> <<ExistingValue/binary, ", ", Value/binary>>
end,

Map1 = maps:put(Name, NewHeaderValue, Map),

set_resp_headers_list(Headers, Map1, Req1).

-spec set_resp_headers(cowboy:http_headers(), Req)
-> Req when Req::req().
Expand Down

0 comments on commit 9af49cd

Please sign in to comment.