diff options
author | Loïc Hoguin <[email protected]> | 2011-12-12 08:18:38 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2011-12-12 08:21:18 +0100 |
commit | f445f16f608fe2942b994014b8ea13d44de9ef8a (patch) | |
tree | 0e751a30bc22ec49e18f4e644b62f16d332e5423 /src | |
parent | a37dd714e0fc8900bc7b7eda35ecfcb465f06043 (diff) | |
download | cowboy-f445f16f608fe2942b994014b8ea13d44de9ef8a.tar.gz cowboy-f445f16f608fe2942b994014b8ea13d44de9ef8a.tar.bz2 cowboy-f445f16f608fe2942b994014b8ea13d44de9ef8a.zip |
Fixes match_media_type in cowboy_http_rest
Based on the patch from Heinz N. Gies. The main change is that his
patch accept values such as */plain which we do not want.
Fixes issue #105.
Diffstat (limited to 'src')
-rw-r--r-- | src/cowboy_http_rest.erl | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/cowboy_http_rest.erl b/src/cowboy_http_rest.erl index a5ae964..d8d2f22 100644 --- a/src/cowboy_http_rest.erl +++ b/src/cowboy_http_rest.erl @@ -247,18 +247,26 @@ choose_media_type(Req, State=#state{content_types_p=CTP}, match_media_type(Req, State, Accept, [], _MediaType) -> choose_media_type(Req, State, Accept); +match_media_type(Req, State, Accept, CTP, + MediaType = {{<<"*">>, <<"*">>, _Params_A}, _QA, _APA}) -> + match_media_type_params(Req, State, Accept, CTP, MediaType); match_media_type(Req, State, Accept, - [Provided = {{Type, SubType_P, Params_P}, _Fun}|Tail], - MediaType = {{Type, SubType_A, Params_A}, _Quality, _AcceptParams}) + CTP = [{{Type, SubType_P, _PP}, _Fun}|_Tail], + MediaType = {{Type, SubType_A, _PA}, _QA, _APA}) when SubType_P =:= SubType_A; SubType_A =:= <<"*">> -> + match_media_type_params(Req, State, Accept, CTP, MediaType); +match_media_type(Req, State, Accept, [_Any|Tail], MediaType) -> + match_media_type(Req, State, Accept, Tail, MediaType). + +match_media_type_params(Req, State, Accept, + [Provided = {{_TP, _STP, Params_P}, _Fun}|Tail], + MediaType = {{_TA, _STA, Params_A}, _QA, _APA}) -> case lists:sort(Params_P) =:= lists:sort(Params_A) of true -> languages_provided(Req, State#state{content_type_a=Provided}); false -> match_media_type(Req, State, Accept, Tail, MediaType) - end; -match_media_type(Req, State, Accept, [_Any|Tail], MediaType) -> - match_media_type(Req, State, Accept, Tail, MediaType). + end. %% languages_provided should return a list of binary values indicating %% which languages are accepted by the resource. |