diff options
author | Loïc Hoguin <[email protected]> | 2013-04-11 17:59:54 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2013-04-11 22:25:36 +0200 |
commit | 5a171d0f8050eda4e43de82efb7f2508be314ee6 (patch) | |
tree | d2d182b9ff779f3f500e94a79b5adfdf831df19b /examples/rest_pastebin/src/toppage_handler.erl | |
parent | 6256429dc97d69cbb19076acfea8e1fc3efb1286 (diff) | |
download | cowboy-5a171d0f8050eda4e43de82efb7f2508be314ee6.tar.gz cowboy-5a171d0f8050eda4e43de82efb7f2508be314ee6.tar.bz2 cowboy-5a171d0f8050eda4e43de82efb7f2508be314ee6.zip |
Remove process_post, post_is_create, create_path, created_path callbacks
Instead it will always go through content_types_accepted and it is
up to the resource code to do any creation and to return the created
path if the method is POST and the client should be redirected to the
created resource's location.
This removes the meta value 'put_path' as it is not needed anymore.
This fixes an issue with PATCH where content types were not normalized.
Diffstat (limited to 'examples/rest_pastebin/src/toppage_handler.erl')
-rw-r--r-- | examples/rest_pastebin/src/toppage_handler.erl | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/examples/rest_pastebin/src/toppage_handler.erl b/examples/rest_pastebin/src/toppage_handler.erl index 5e904d9..a6a0829 100644 --- a/examples/rest_pastebin/src/toppage_handler.erl +++ b/examples/rest_pastebin/src/toppage_handler.erl @@ -9,8 +9,6 @@ -export([content_types_provided/2]). -export([content_types_accepted/2]). -export([resource_exists/2]). --export([post_is_create/2]). --export([create_path/2]). %% Callback Callbacks -export([create_paste/2]). @@ -47,17 +45,16 @@ resource_exists(Req, _State) -> end end. -post_is_create(Req, State) -> - {true, Req, State}. - -create_path(Req, State) -> - {<<$/, (new_paste_id())/binary>>, Req, State}. - create_paste(Req, State) -> {<<$/, PasteID/binary>>, Req2} = cowboy_req:meta(put_path, Req), {ok, [{<<"paste">>, Paste}], Req3} = cowboy_req:body_qs(Req2), ok = file:write_file(full_path(PasteID), Paste), - {true, Req3, State}. + case cowboy_req:method(Req3) of + {<<"POST">>, Req4} -> + {<<$/, (new_paste_id())/binary>>, Req4, State}; + {_, Req4} -> + {true, Req4, State} + end. paste_html(Req, index) -> {read_file("index.html"), Req, index}; |