aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2013-05-31 18:31:28 +0200
committerLoïc Hoguin <[email protected]>2013-05-31 18:38:43 +0200
commit4fde6cba94f4ae65b6434aa722c08c60066f67d7 (patch)
treec5b555f5e1c7a494093486f462c5632a163f2cda /src
parent8fac4eedcf7d658f2933cbb77b4d8fe62429e3d6 (diff)
downloadcowboy-4fde6cba94f4ae65b6434aa722c08c60066f67d7.tar.gz
cowboy-4fde6cba94f4ae65b6434aa722c08c60066f67d7.tar.bz2
cowboy-4fde6cba94f4ae65b6434aa722c08c60066f67d7.zip
In content-types, the charset parameter is converted to lowercase
We know this specific parameter is case insensitive so we automatically lowercase it to make things simpler to the developer.
Diffstat (limited to 'src')
-rw-r--r--src/cowboy_http.erl20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/cowboy_http.erl b/src/cowboy_http.erl
index af60dd9..d2bdf3b 100644
--- a/src/cowboy_http.erl
+++ b/src/cowboy_http.erl
@@ -162,14 +162,26 @@ cookie_value(<< C, Rest/binary >>, Fun, Acc) ->
cookie_value(Rest, Fun, << Acc/binary, C >>).
%% @doc Parse a content type.
+%%
+%% We lowercase the charset header as we know it's case insensitive.
-spec content_type(binary()) -> any().
content_type(Data) ->
media_type(Data,
fun (Rest, Type, SubType) ->
- params(Rest,
- fun (<<>>, Params) -> {Type, SubType, Params};
- (_Rest2, _) -> {error, badarg}
- end)
+ params(Rest,
+ fun (<<>>, Params) ->
+ case lists:keyfind(<<"charset">>, 1, Params) of
+ false ->
+ {Type, SubType, Params};
+ {_, Charset} ->
+ Charset2 = cowboy_bstr:to_lower(Charset),
+ Params2 = lists:keyreplace(<<"charset">>,
+ 1, Params, {<<"charset">>, Charset2}),
+ {Type, SubType, Params2}
+ end;
+ (_Rest2, _) ->
+ {error, badarg}
+ end)
end).
%% @doc Parse a media range.