Skip to content

Commit

Permalink
handle iodata
Browse files Browse the repository at this point in the history
  • Loading branch information
geeksilva97 committed Apr 19, 2024
1 parent d43807d commit ded96a1
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/cowboy_req.erl
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,17 @@ resp_headers_test() ->
{<<"Name">>, <<"Cormano">>},
{<<"Name">>, <<"Paco">>},
{<<"X-MyHeader">>, <<"custom-header">>},
{<<"api-key">>, "My api"},
{<<"api-key">>, "KEY"}
{<<"game-name">>, "Sunset"},
{<<"game-name">>, "Riders"},
{<<"header">>, ["io", "data"]},
{<<"header">>, ["header"]}
], #{}, Req),

#{
<<"Name">> := <<"Cormano, Paco">>,
<<"X-MyHeader">> := <<"custom-header">>
<<"X-MyHeader">> := <<"custom-header">>,
<<"game-name">> := <<"Sunset, Riders">>,
<<"header">> := <<"iodata, header">>
} = RespHeaders,

ok.
Expand Down Expand Up @@ -757,12 +761,14 @@ set_resp_headers_list(HeaderTupleList, Req) ->
set_resp_headers_list([], Map, Req) ->
set_resp_headers(Map, Req);

set_resp_headers_list([{<<"set-cookie">>, Value} | Headers], Map, Req) ->
set_resp_headers_list([{<<"set-cookie">>, _} | Headers], Map, Req) ->
set_resp_headers_list(Headers, Map, Req);
set_resp_headers_list([{Name, Value} | Headers], Map, Req) ->
BinaryValue = iolist_to_binary(Value),
NewHeaderValue = case maps:get(Name, Map, undefined) of
undefined -> Value;
ExistingValue -> <<ExistingValue/binary, ", ", Value/binary>>
undefined -> BinaryValue;
ExistingValue ->
<<ExistingValue/binary, ", ", BinaryValue/binary>>
end,

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

0 comments on commit ded96a1

Please sign in to comment.