0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 12:20:24 +00:00

updated documentation on AcceptCallback and removed test case for deprecated return value

This commit is contained in:
Martin Björklund 2020-10-07 13:50:03 +02:00
parent fa5af5dce4
commit aabac3f2d7
3 changed files with 10 additions and 17 deletions

View file

@ -89,7 +89,6 @@ AcceptCallback(Req, State) -> {Result, Req, State}
Result :: true Result :: true
| {created, URI :: iodata()} | {created, URI :: iodata()}
| {see_other, URI :: iodata()} | {see_other, URI :: iodata()}
| {true, URI :: iodata()}
| false | false
Default - crash Default - crash
---- ----
@ -105,8 +104,12 @@ that is being created or replaced.
For POST requests, the body is typically application-specific For POST requests, the body is typically application-specific
instructions on how to process the request, but it may also be a instructions on how to process the request, but it may also be a
representation of the resource. When creating a new resource with POST representation of the resource. When creating a new resource with POST
at a different location, return `{create, URI}` or `{see_other, URI`} at a different location, return `{created, URI}` or `{see_other, URI`}
with `URI` the new location. The return value `{true, URI}` is deprecated. with `URI` the new location.
Returning `{created, URI`} will result in a '201 Created' response.
Returning `{see_other, URI`} will result in a '303 See Other' response.
For PATCH requests, the body is a series of instructions on For PATCH requests, the body is a series of instructions on
how to update the resource. Patch files or JSON Patch are how to update the resource. Patch files or JSON Patch are
@ -728,6 +731,9 @@ listed here, like the authorization header.
== Changelog == Changelog
* *2.9*: An `AcceptCallback` can now return `{created, URI}` and
`{see_other, URI}`. The old return value `{true, URI}` is
deprecated.
* *2.7*: The media type wildcard in `content_types_accepted` * *2.7*: The media type wildcard in `content_types_accepted`
is now documented. is now documented.
* *2.6*: The callback `rate_limited` was added. * *2.6*: The callback `rate_limited` was added.

View file

@ -24,7 +24,5 @@ from_text(Req=#{qs := Qs}, State) ->
<<"created">> -> <<"created">> ->
{{created, NewURI}, Req, State}; {{created, NewURI}, Req, State};
<<"see_other">> -> <<"see_other">> ->
{{see_other, NewURI}, Req, State}; {{see_other, NewURI}, Req, State}
_ ->
{{true, NewURI}, Req, State}
end. end.

View file

@ -497,17 +497,6 @@ create_resource_see_other(Config) ->
{response, _, 303, _} = gun:await(ConnPid, Ref), {response, _, 303, _} = gun:await(ConnPid, Ref),
ok. ok.
create_resource_legacy(Config) ->
doc("POST to an existing resource to create a new resource. "
"When the accept callback returns {true, NewURI}, the legacy "
"behavior is a 302 See Other reply."),
ConnPid = gun_open(Config),
Ref = gun:post(ConnPid, "/create_resource", [
{<<"content-type">>, <<"application/text">>}
], <<"hello">>, #{}),
{response, _, 303, _} = gun:await(ConnPid, Ref),
ok.
error_on_malformed_accept(Config) -> error_on_malformed_accept(Config) ->
doc("A malformed Accept header must result in a 400 response."), doc("A malformed Accept header must result in a 400 response."),
do_error_on_malformed_header(Config, <<"accept">>). do_error_on_malformed_header(Config, <<"accept">>).