mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-15 12:40:25 +00:00
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.
This commit is contained in:
parent
8fac4eedcf
commit
4fde6cba94
5 changed files with 54 additions and 10 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue