aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2012-07-21 19:02:01 +0200
committerLoïc Hoguin <[email protected]>2012-07-21 21:01:45 +0200
commit3d1ddd1d8a69bd4a68b2fa555cc0146c7c1f04da (patch)
tree0a7a686735f9ce93b06dea5ef72e36aa2eb9a8d1 /src
parent95ed1348c3ba6006c7bb9cf5025b79ab550901a0 (diff)
downloadcowboy-3d1ddd1d8a69bd4a68b2fa555cc0146c7c1f04da.tar.gz
cowboy-3d1ddd1d8a69bd4a68b2fa555cc0146c7c1f04da.tar.bz2
cowboy-3d1ddd1d8a69bd4a68b2fa555cc0146c7c1f04da.zip
REST: Normalize content types accepted
Same as content types provided, we accept the <<"application/json">> form.
Diffstat (limited to 'src')
-rw-r--r--src/cowboy_http_rest.erl11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/cowboy_http_rest.erl b/src/cowboy_http_rest.erl
index a0bcc13..463f76b 100644
--- a/src/cowboy_http_rest.erl
+++ b/src/cowboy_http_rest.erl
@@ -203,7 +203,7 @@ content_types_provided(Req=#http_req{meta=Meta}, State) ->
{[], Req2, HandlerState} ->
not_acceptable(Req2, State#state{handler_state=HandlerState});
{CTP, Req2, HandlerState} ->
- CTP2 = [normalize_content_types_provided(P) || P <- CTP],
+ CTP2 = [normalize_content_types(P) || P <- CTP],
State2 = State#state{
handler_state=HandlerState, content_types_p=CTP2},
{Accept, Req3} = cowboy_http_req:parse_header('Accept', Req2),
@@ -219,10 +219,10 @@ content_types_provided(Req=#http_req{meta=Meta}, State) ->
end
end.
-normalize_content_types_provided({ContentType, Handler})
+normalize_content_types({ContentType, Callback})
when is_binary(ContentType) ->
- {cowboy_http:content_type(ContentType), Handler};
-normalize_content_types_provided(Provided) ->
+ {cowboy_http:content_type(ContentType), Callback};
+normalize_content_types(Provided) ->
Provided.
prioritize_accept(Accept) ->
@@ -724,10 +724,11 @@ put_resource(Req, State, OnTrue) ->
{halt, Req2, HandlerState} ->
terminate(Req2, State#state{handler_state=HandlerState});
{CTA, Req2, HandlerState} ->
+ CTA2 = [normalize_content_types(P) || P <- CTA],
State2 = State#state{handler_state=HandlerState},
{ContentType, Req3}
= cowboy_http_req:parse_header('Content-Type', Req2),
- choose_content_type(Req3, State2, OnTrue, ContentType, CTA)
+ choose_content_type(Req3, State2, OnTrue, ContentType, CTA2)
end.
%% The special content type '*' will always match. It can be used as a