aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2013-01-29 21:24:04 +0100
committerLoïc Hoguin <[email protected]>2013-01-29 21:24:04 +0100
commitec52b4f4df70a114bca56a19535739ae3788166a (patch)
tree092ef2ed715873bc2595a409d43d04c9dba956c1 /src
parentfd5a977a39ec99d0aa57a2864f91cca7af5c67d6 (diff)
parent8a798014e980d596e631cf5f24957ee15f9a1ac4 (diff)
downloadcowboy-ec52b4f4df70a114bca56a19535739ae3788166a.tar.gz
cowboy-ec52b4f4df70a114bca56a19535739ae3788166a.tar.bz2
cowboy-ec52b4f4df70a114bca56a19535739ae3788166a.zip
Merge branch 'rest_post_created_path' of https://github.com/treetopllc/cowboy
Diffstat (limited to 'src')
-rw-r--r--src/cowboy_rest.erl19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/cowboy_rest.erl b/src/cowboy_rest.erl
index fb7f2e1..8967b1d 100644
--- a/src/cowboy_rest.erl
+++ b/src/cowboy_rest.erl
@@ -670,6 +670,8 @@ post_is_create(Req, State) ->
%% (including the leading /).
create_path(Req, State) ->
case call(Req, State, create_path) of
+ no_call ->
+ put_resource(Req, State, fun created_path/2);
{halt, Req2, HandlerState} ->
terminate(Req2, State#state{handler_state=HandlerState});
{Path, Req2, HandlerState} ->
@@ -681,6 +683,23 @@ create_path(Req, State) ->
State2, 303)
end.
+%% Called after content_types_accepted is called for POST methods
+%% when create_path did not exist. Expects the full path to
+%% be returned and MUST exist in the case that create_path
+%% does not.
+created_path(Req, State) ->
+ case call(Req, State, created_path) of
+ {halt, Req2, HandlerState} ->
+ terminate(Req2, State#state{handler_state=HandlerState});
+ {Path, Req2, HandlerState} ->
+ {HostURL, Req3} = cowboy_req:host_url(Req2),
+ State2 = State#state{handler_state=HandlerState},
+ Req4 = cowboy_req:set_resp_header(
+ <<"Location">>, << HostURL/binary, Path/binary >>, Req3),
+ respond(cowboy_req:set_meta(put_path, Path, Req4),
+ State2, 303)
+ end.
+
%% process_post should return true when the POST body could be processed
%% and false when it hasn't, in which case a 500 error is sent.
process_post(Req, State) ->