aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_multipart.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2012-09-21 13:07:51 +0200
committerLoïc Hoguin <[email protected]>2012-09-21 13:07:51 +0200
commite27fd5fcb9786bed45976a3e4322bc89d3ffc025 (patch)
treedf7ecdeacb2eeff7145337d0d6e7a1b5cc279b1b /src/cowboy_multipart.erl
parent34021666cbf626e979ea136664b1f8beca893d6f (diff)
downloadcowboy-e27fd5fcb9786bed45976a3e4322bc89d3ffc025.tar.gz
cowboy-e27fd5fcb9786bed45976a3e4322bc89d3ffc025.tar.bz2
cowboy-e27fd5fcb9786bed45976a3e4322bc89d3ffc025.zip
Make multipart part headers binary lowercase
Here we do not remove decode_packet yet, we just lowercase the header name and transform it into a binary if needed, to fix the consistency issue.
Diffstat (limited to 'src/cowboy_multipart.erl')
-rw-r--r--src/cowboy_multipart.erl14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/cowboy_multipart.erl b/src/cowboy_multipart.erl
index 4040073..fc889ef 100644
--- a/src/cowboy_multipart.erl
+++ b/src/cowboy_multipart.erl
@@ -23,7 +23,7 @@
-type more(T) :: T | {more, parser(T)}.
-type part_result() :: headers() | eof.
-type headers() :: {headers, http_headers(), body_cont()}.
--type http_headers() :: [{atom() | binary(), binary()}].
+-type http_headers() :: [{binary(), binary()}].
-type body_cont() :: cont(more(body_result())).
-type cont(T) :: fun(() -> T).
-type body_result() :: {body, binary(), body_cont()} | end_of_part().
@@ -135,7 +135,11 @@ parse_headers(Bin, Pattern) ->
parse_headers(Bin, Pattern, Acc) ->
case erlang:decode_packet(httph_bin, Bin, []) of
{ok, {http_header, _, Name, _, Value}, Rest} ->
- parse_headers(Rest, Pattern, [{Name, Value} | Acc]);
+ Name2 = case is_atom(Name) of
+ true -> cowboy_bstr:to_lower(atom_to_binary(Name, latin1));
+ false -> cowboy_bstr:to_lower(Name)
+ end,
+ parse_headers(Rest, Pattern, [{Name2, Value} | Acc]);
{ok, http_eoh, Rest} ->
Headers = lists:reverse(Acc),
{headers, Headers, fun () -> parse_body(Rest, Pattern) end};
@@ -205,7 +209,7 @@ multipart_test_() ->
{<<"preamble\r\n--boundary--">>, []},
{<<"--boundary--\r\nepilogue">>, []},
{<<"\r\n--boundary\r\nA:b\r\nC:d\r\n\r\n\r\n--boundary--">>,
- [{[{<<"A">>, <<"b">>}, {<<"C">>, <<"d">>}], <<>>}]},
+ [{[{<<"a">>, <<"b">>}, {<<"c">>, <<"d">>}], <<>>}]},
{
<<
"--boundary\r\nX-Name:answer\r\n\r\n42"
@@ -213,8 +217,8 @@ multipart_test_() ->
"\r\n--boundary--"
>>,
[
- {[{<<"X-Name">>, <<"answer">>}], <<"42">>},
- {[{'Server', <<"Cowboy">>}], <<"It rocks!\r\n">>}
+ {[{<<"x-name">>, <<"answer">>}], <<"42">>},
+ {[{<<"server">>, <<"Cowboy">>}], <<"It rocks!\r\n">>}
]
}
],