diff options
author | Martin Björklund <[email protected]> | 2020-09-11 12:35:36 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2020-11-27 16:17:43 +0100 |
commit | 8795233c57f1f472781a22ffbf186ce38cc5b049 (patch) | |
tree | 140478621afdef80d4957e17e417a2751ef7694c /test/handlers/create_resource_h.erl | |
parent | 63a6b86fbae1190ba78dceb196588fdcae50e17a (diff) | |
download | cowboy-8795233c57f1f472781a22ffbf186ce38cc5b049.tar.gz cowboy-8795233c57f1f472781a22ffbf186ce38cc5b049.tar.bz2 cowboy-8795233c57f1f472781a22ffbf186ce38cc5b049.zip |
AcceptCallback may now return created/see_other tuples for POST
They replace and deprecate the {true,URI} return value.
Diffstat (limited to 'test/handlers/create_resource_h.erl')
-rw-r--r-- | test/handlers/create_resource_h.erl | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/handlers/create_resource_h.erl b/test/handlers/create_resource_h.erl new file mode 100644 index 0000000..f82e610 --- /dev/null +++ b/test/handlers/create_resource_h.erl @@ -0,0 +1,28 @@ +-module(create_resource_h). + +-export([init/2]). +-export([allowed_methods/2]). +-export([resource_exists/2]). +-export([content_types_accepted/2]). +-export([from_text/2]). + +init(Req, Opts) -> + {cowboy_rest, Req, Opts}. + +allowed_methods(Req, State) -> + {[<<"POST">>], Req, State}. + +resource_exists(Req, State) -> + {true, Req, State}. + +content_types_accepted(Req, State) -> + {[{{<<"application">>, <<"text">>, []}, from_text}], Req, State}. + +from_text(Req=#{qs := Qs}, State) -> + NewURI = [cowboy_req:uri(Req), "/foo"], + case Qs of + <<"created">> -> + {{created, NewURI}, Req, State}; + <<"see_other">> -> + {{see_other, NewURI}, Req, State} + end. |