aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2013-11-09 18:26:49 +0100
committerLoïc Hoguin <[email protected]>2013-11-09 18:26:49 +0100
commit5d27d4d1758a56f12913576ffc85ec73792bdc42 (patch)
tree79b4713f2815e5e99db5de7ffd5728067aad9699
parenta0205779fe98002f9deebaef446067dc29e2deb9 (diff)
downloadcowboy-5d27d4d1758a56f12913576ffc85ec73792bdc42.tar.gz
cowboy-5d27d4d1758a56f12913576ffc85ec73792bdc42.tar.bz2
cowboy-5d27d4d1758a56f12913576ffc85ec73792bdc42.zip
Properly send 201 on PUT requests when resource didn't exist
Regardless of whether a location header has been set, as explained in the HTTP RFC.
-rw-r--r--src/cowboy_rest.erl8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/cowboy_rest.erl b/src/cowboy_rest.erl
index 862ebbf..30ed15d 100644
--- a/src/cowboy_rest.erl
+++ b/src/cowboy_rest.erl
@@ -801,8 +801,12 @@ process_content_type(Req, State=#state{method=Method, exists=Exists}, Fun) ->
error_terminate(Req, State, Class, Reason, Fun)
end.
-%% If the resource is new and has been created at another location
-%% we send a 201. Otherwise we continue as normal.
+%% If PUT was used then the resource has been created at the current URL.
+%% Otherwise, if a location header has been set then the resource has been
+%% created at a new URL. If not, send a 200 or 204 as expected from a
+%% POST or PATCH request.
+maybe_created(Req, State=#state{method= <<"PUT">>}) ->
+ respond(Req, State, 201);
maybe_created(Req, State) ->
case cowboy_req:has_resp_header(<<"location">>, Req) of
true -> respond(Req, State, 201);