aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2012-03-13 00:46:56 +0100
committerLoïc Hoguin <[email protected]>2012-03-13 01:43:15 +0100
commite87f51e542a9ee5bdcadd5841731b32210732e08 (patch)
treee8dcc10b7f35682995d3b688f76c50e66e1e8b64
parent133564d0286fa23787bbe7a660db6f79073bd252 (diff)
parent21cd61cb388fe1037a618fcd4a2f7918e6b4c112 (diff)
downloadcowboy-e87f51e542a9ee5bdcadd5841731b32210732e08.tar.gz
cowboy-e87f51e542a9ee5bdcadd5841731b32210732e08.tar.bz2
cowboy-e87f51e542a9ee5bdcadd5841731b32210732e08.zip
Merge branch 'content-type-accepted-asterisk-atom' of https://github.com/dysinger/cowboy
Added a comment explaining the '*' always matching.
-rw-r--r--src/cowboy_http_rest.erl8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/cowboy_http_rest.erl b/src/cowboy_http_rest.erl
index 8bce1d4..c19d838 100644
--- a/src/cowboy_http_rest.erl
+++ b/src/cowboy_http_rest.erl
@@ -729,10 +729,14 @@ put_resource(Req, State, OnTrue) ->
choose_content_type(Req3, State2, OnTrue, ContentType, CTA)
end.
+%% The special content type '*' will always match. It can be used as a
+%% catch-all content type for accepting any kind of request content.
+%% Note that because it will always match, it should be the last of the
+%% list of content types, otherwise it'll shadow the ones following.
choose_content_type(Req, State, _OnTrue, _ContentType, []) ->
respond(Req, State, 415);
-choose_content_type(Req, State, OnTrue, ContentType,
- [{Accepted, Fun}|_Tail]) when ContentType =:= Accepted ->
+choose_content_type(Req, State, OnTrue, ContentType, [{Accepted, Fun}|_Tail])
+ when Accepted =:= '*' orelse Accepted =:= ContentType ->
case call(Req, State, Fun) of
{halt, Req2, HandlerState} ->
terminate(Req2, State#state{handler_state=HandlerState});