aboutsummaryrefslogtreecommitdiffstats
path: root/test/handlers
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2018-11-22 00:12:18 +0100
committerLoïc Hoguin <[email protected]>2018-11-22 00:12:18 +0100
commit0223f69fcd2252a4b686b2815e6ee287b1484551 (patch)
treeadc934ca725cd23d7e7a76514ae732bbc62c3cac /test/handlers
parent037b286aa85acaaf439011bd7d2ae38685ce2f2e (diff)
downloadcowboy-0223f69fcd2252a4b686b2815e6ee287b1484551.tar.gz
cowboy-0223f69fcd2252a4b686b2815e6ee287b1484551.tar.bz2
cowboy-0223f69fcd2252a4b686b2815e6ee287b1484551.zip
Move the final old HTTP suite tests and remove it
Diffstat (limited to 'test/handlers')
-rw-r--r--test/handlers/accept_callback_h.erl23
-rw-r--r--test/handlers/content_types_accepted_h.erl6
-rw-r--r--test/handlers/delete_resource_h.erl17
-rw-r--r--test/handlers/generate_etag_h.erl39
4 files changed, 83 insertions, 2 deletions
diff --git a/test/handlers/accept_callback_h.erl b/test/handlers/accept_callback_h.erl
new file mode 100644
index 0000000..1912e9f
--- /dev/null
+++ b/test/handlers/accept_callback_h.erl
@@ -0,0 +1,23 @@
+%% This module returns something different in
+%% AcceptCallback depending on the query string.
+
+-module(accept_callback_h).
+
+-export([init/2]).
+-export([allowed_methods/2]).
+-export([content_types_accepted/2]).
+-export([put_text_plain/2]).
+
+init(Req, Opts) ->
+ {cowboy_rest, Req, Opts}.
+
+allowed_methods(Req, State) ->
+ {[<<"PUT">>, <<"POST">>, <<"PATCH">>], Req, State}.
+
+content_types_accepted(Req, State) ->
+ {[{{<<"text">>, <<"plain">>, []}, put_text_plain}], Req, State}.
+
+put_text_plain(Req=#{qs := <<"false">>}, State) ->
+ {false, Req, State};
+put_text_plain(Req=#{qs := <<"true">>}, State) ->
+ {true, Req, State}.
diff --git a/test/handlers/content_types_accepted_h.erl b/test/handlers/content_types_accepted_h.erl
index b871dc8..d34135e 100644
--- a/test/handlers/content_types_accepted_h.erl
+++ b/test/handlers/content_types_accepted_h.erl
@@ -1,5 +1,5 @@
-%% This module accepts a multipart media type with parameters
-%% that do not include boundary.
+%% This module returns something different in
+%% content_types_accepted depending on the query string.
-module(content_types_accepted_h).
@@ -19,6 +19,8 @@ content_types_accepted(Req=#{qs := <<"multipart">>}, State) ->
{[
{{<<"multipart">>, <<"mixed">>, [{<<"v">>, <<"1">>}]}, put_multipart_mixed}
], Req, State};
+content_types_accepted(Req=#{qs := <<"param">>}, State) ->
+ {[{{<<"text">>, <<"plain">>, [{<<"charset">>, <<"utf-8">>}]}, put_text_plain}], Req, State};
content_types_accepted(Req=#{qs := <<"wildcard-param">>}, State) ->
{[{{<<"text">>, <<"plain">>, '*'}, put_text_plain}], Req, State}.
diff --git a/test/handlers/delete_resource_h.erl b/test/handlers/delete_resource_h.erl
new file mode 100644
index 0000000..f7202a9
--- /dev/null
+++ b/test/handlers/delete_resource_h.erl
@@ -0,0 +1,17 @@
+%% This module accepts a multipart media type with parameters
+%% that do not include boundary.
+
+-module(delete_resource_h).
+
+-export([init/2]).
+-export([allowed_methods/2]).
+-export([delete_resource/2]).
+
+init(Req, Opts) ->
+ {cowboy_rest, Req, Opts}.
+
+allowed_methods(Req, State) ->
+ {[<<"DELETE">>], Req, State}.
+
+delete_resource(#{qs := <<"missing">>}, _) ->
+ no_call.
diff --git a/test/handlers/generate_etag_h.erl b/test/handlers/generate_etag_h.erl
new file mode 100644
index 0000000..97ee82b
--- /dev/null
+++ b/test/handlers/generate_etag_h.erl
@@ -0,0 +1,39 @@
+%% This module sends a different etag value
+%% depending on the query string.
+
+-module(generate_etag_h).
+
+-export([init/2]).
+-export([content_types_provided/2]).
+-export([get_text_plain/2]).
+-export([generate_etag/2]).
+
+init(Req, Opts) ->
+ {cowboy_rest, Req, Opts}.
+
+content_types_provided(Req, State) ->
+ {[{{<<"text">>, <<"plain">>, []}, get_text_plain}], Req, State}.
+
+get_text_plain(Req, State) ->
+ {<<"This is REST!">>, Req, State}.
+
+%% Correct return values from generate_etag/2.
+generate_etag(Req=#{qs := <<"tuple-weak">>}, State) ->
+ {{weak, <<"etag-header-value">>}, Req, State};
+generate_etag(Req=#{qs := <<"tuple-strong">>}, State) ->
+ {{strong, <<"etag-header-value">>}, Req, State};
+%% Backwards compatible return values from generate_etag/2.
+generate_etag(Req=#{qs := <<"binary-weak-quoted">>}, State) ->
+ {<<"W/\"etag-header-value\"">>, Req, State};
+generate_etag(Req=#{qs := <<"binary-strong-quoted">>}, State) ->
+ {<<"\"etag-header-value\"">>, Req, State};
+%% Invalid return values from generate_etag/2.
+generate_etag(Req=#{qs := <<"binary-weak-unquoted">>}, State) ->
+ ct_helper_error_h:ignore(cow_http_hd, parse_etag, 1),
+ {<<"W/etag-header-value">>, Req, State};
+generate_etag(Req=#{qs := <<"binary-strong-unquoted">>}, State) ->
+ ct_helper_error_h:ignore(cow_http_hd, parse_etag, 1),
+ {<<"etag-header-value">>, Req, State};
+%% Simulate the callback being missing in other cases.
+generate_etag(#{qs := <<"missing">>}, _) ->
+ no_call.