aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorTom Burdick <[email protected]>2012-01-23 16:10:41 -0600
committerLoïc Hoguin <[email protected]>2012-01-26 18:21:20 +0100
commitca42ea16201acf34e2db436defacf3bde7ac03ca (patch)
treed07de1a9048183fa0086ebd5b8e691d6e8d2a00e /test
parent4b93c2d19a10e5d9cee207038103bb83f1ab9436 (diff)
downloadcowboy-ca42ea16201acf34e2db436defacf3bde7ac03ca.tar.gz
cowboy-ca42ea16201acf34e2db436defacf3bde7ac03ca.tar.bz2
cowboy-ca42ea16201acf34e2db436defacf3bde7ac03ca.zip
Handle delete better when no delete_resource function is implemented
Diffstat (limited to 'test')
-rw-r--r--test/http_SUITE.erl18
-rw-r--r--test/rest_nodelete_resource.erl17
2 files changed, 32 insertions, 3 deletions
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}.
+