aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/cowboy_http_rest.erl2
-rw-r--r--test/http_SUITE.erl18
-rw-r--r--test/rest_nodelete_resource.erl17
3 files changed, 33 insertions, 4 deletions
diff --git a/src/cowboy_http_rest.erl b/src/cowboy_http_rest.erl
index e6cc6ff..392b172 100644
--- a/src/cowboy_http_rest.erl
+++ b/src/cowboy_http_rest.erl
@@ -648,7 +648,7 @@ method(Req, State) ->
%% delete_resource/2 should start deleting the resource and return.
delete_resource(Req, State) ->
- expect(Req, State, delete_resource, true, fun delete_completed/2, 500).
+ expect(Req, State, delete_resource, false, 500, fun delete_completed/2).
%% delete_completed/2 indicates whether the resource has been deleted yet.
delete_completed(Req, State) ->
diff --git a/test/http_SUITE.erl b/test/http_SUITE.erl
index bad91a8..29fe4c3 100644
--- a/test/http_SUITE.erl
+++ b/test/http_SUITE.erl
@@ -29,7 +29,7 @@
file_200/1, file_403/1, dir_403/1, file_404/1,
file_400/1]). %% http and https.
-export([http_10_hostless/1]). %% misc.
--export([rest_simple/1, rest_keepalive/1, rest_keepalive_post/1]). %% rest.
+-export([rest_simple/1, rest_keepalive/1, rest_keepalive_post/1, rest_nodelete/1]). %% rest.
%% ct.
@@ -47,7 +47,7 @@ groups() ->
static_function_etag, multipart] ++ BaseTests},
{https, [], BaseTests},
{misc, [], [http_10_hostless]},
- {rest, [], [rest_simple, rest_keepalive, rest_keepalive_post]}].
+ {rest, [], [rest_simple, rest_keepalive, rest_keepalive_post, rest_nodelete]}].
init_per_suite(Config) ->
application:start(inets),
@@ -97,7 +97,8 @@ init_per_group(rest, Config) ->
cowboy_http_protocol, [{dispatch, [{'_', [
{[<<"simple">>], rest_simple_resource, []},
{[<<"forbidden_post">>], rest_forbidden_resource, [true]},
- {[<<"simple_post">>], rest_forbidden_resource, [false]}
+ {[<<"simple_post">>], rest_forbidden_resource, [false]},
+ {[<<"nodelete">>], rest_nodelete_resource, []}
]}]}]),
[{port, Port}|Config].
@@ -611,3 +612,14 @@ rest_keepalive_post_loop(Socket, N, forbidden_post) ->
{0, 12} = binary:match(Data, <<"HTTP/1.1 403">>),
nomatch = binary:match(Data, <<"Connection: close">>),
rest_keepalive_post_loop(Socket, N - 1, simple_post).
+
+rest_nodelete(Config) ->
+ {port, Port} = lists:keyfind(port, 1, Config),
+ {ok, Socket} = gen_tcp:connect("localhost", Port,
+ [binary, {active, false}, {packet, raw}]),
+ Request = "DELETE /nodelete HTTP/1.1\r\nHost: localhost\r\n\r\n",
+ ok = gen_tcp:send(Socket, Request),
+ {ok, Data} = gen_tcp:recv(Socket, 0, 6000),
+ ct:print("response ~p~n", [Data]),
+ {0, 12} = binary:match(Data, <<"HTTP/1.1 500">>),
+ ok = gen_tcp:close(Socket).
diff --git a/test/rest_nodelete_resource.erl b/test/rest_nodelete_resource.erl
new file mode 100644
index 0000000..e0ece5a
--- /dev/null
+++ b/test/rest_nodelete_resource.erl
@@ -0,0 +1,17 @@
+-module(rest_nodelete_resource).
+-export([init/3, allowed_methods/2, content_types_provided/2,
+ get_text_plain/2]).
+
+init(_Transport, _Req, _Opts) ->
+ {upgrade, protocol, cowboy_http_rest}.
+
+allowed_methods(Req, State) ->
+ {['GET', 'HEAD', 'DELETE'], Req, State}.
+
+
+content_types_provided(Req, State) ->
+ {[{{<<"text">>, <<"plain">>, []}, get_text_plain}], Req, State}.
+
+get_text_plain(Req, State) ->
+ {<<"This is REST!">>, Req, State}.
+