mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 12:20:24 +00:00
AcceptCallback may now return created/see_other tuples for POST
They replace and deprecate the {true,URI} return value.
This commit is contained in:
parent
63a6b86fba
commit
8795233c57
4 changed files with 73 additions and 4 deletions
28
test/handlers/create_resource_h.erl
Normal file
28
test/handlers/create_resource_h.erl
Normal file
|
@ -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.
|
Loading…
Add table
Add a link
Reference in a new issue