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/rest_handler_SUITE.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/rest_handler_SUITE.erl')
-rw-r--r-- | test/rest_handler_SUITE.erl | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/test/rest_handler_SUITE.erl b/test/rest_handler_SUITE.erl index 43695c3..1667565 100644 --- a/test/rest_handler_SUITE.erl +++ b/test/rest_handler_SUITE.erl @@ -52,6 +52,7 @@ init_dispatch(_) -> {"/content_types_accepted", content_types_accepted_h, []}, {"/content_types_provided", content_types_provided_h, []}, {"/delete_resource", delete_resource_h, []}, + {"/create_resource", create_resource_h, []}, {"/expires", expires_h, []}, {"/generate_etag", generate_etag_h, []}, {"/if_range", if_range_h, []}, @@ -474,6 +475,29 @@ delete_resource_missing(Config) -> {response, _, 500, _} = gun:await(ConnPid, Ref), ok. +create_resource_created(Config) -> + doc("POST to an existing resource to create a new resource. " + "When the accept callback returns {created, NewURI}, " + "the expected reply is 201 Created."), + ConnPid = gun_open(Config), + Ref = gun:post(ConnPid, "/create_resource?created", [ + {<<"content-type">>, <<"application/text">>} + ], <<"hello">>, #{}), + {response, _, 201, _} = gun:await(ConnPid, Ref), + ok. + +create_resource_see_other(Config) -> + doc("POST to an existing resource to create a new resource. " + "When the accept callback returns {see_other, NewURI}, " + "the expected reply is 303 See Other with a location header set."), + ConnPid = gun_open(Config), + Ref = gun:post(ConnPid, "/create_resource?see_other", [ + {<<"content-type">>, <<"application/text">>} + ], <<"hello">>, #{}), + {response, _, 303, RespHeaders} = gun:await(ConnPid, Ref), + {_, _} = lists:keyfind(<<"location">>, 1, RespHeaders), + ok. + error_on_malformed_accept(Config) -> doc("A malformed Accept header must result in a 400 response."), do_error_on_malformed_header(Config, <<"accept">>). |