diff options
Diffstat (limited to 'test/handlers')
-rw-r--r-- | test/handlers/accept_callback_missing_h.erl | 15 | ||||
-rw-r--r-- | test/handlers/content_types_accepted_h.erl | 9 | ||||
-rw-r--r-- | test/handlers/content_types_provided_h.erl | 24 | ||||
-rw-r--r-- | test/handlers/expires_h.erl | 28 | ||||
-rw-r--r-- | test/handlers/last_modified_h.erl | 24 |
5 files changed, 99 insertions, 1 deletions
diff --git a/test/handlers/accept_callback_missing_h.erl b/test/handlers/accept_callback_missing_h.erl new file mode 100644 index 0000000..c97f123 --- /dev/null +++ b/test/handlers/accept_callback_missing_h.erl @@ -0,0 +1,15 @@ +-module(accept_callback_missing_h). + +-export([init/2]). +-export([allowed_methods/2]). +-export([content_types_accepted/2]). + +init(Req, State) -> + {cowboy_rest, Req, State}. + +allowed_methods(Req, State) -> + {[<<"PUT">>], Req, State}. + +content_types_accepted(Req, State) -> + ct_helper_error_h:ignore(cowboy_rest, process_content_type, 3), + {[{<<"text/plain">>, accept}], Req, State}. diff --git a/test/handlers/content_types_accepted_h.erl b/test/handlers/content_types_accepted_h.erl index 7aec1bb..b871dc8 100644 --- a/test/handlers/content_types_accepted_h.erl +++ b/test/handlers/content_types_accepted_h.erl @@ -7,6 +7,7 @@ -export([allowed_methods/2]). -export([content_types_accepted/2]). -export([put_multipart_mixed/2]). +-export([put_text_plain/2]). init(Req, Opts) -> {cowboy_rest, Req, Opts}. @@ -17,7 +18,13 @@ allowed_methods(Req, State) -> content_types_accepted(Req=#{qs := <<"multipart">>}, State) -> {[ {{<<"multipart">>, <<"mixed">>, [{<<"v">>, <<"1">>}]}, put_multipart_mixed} - ], Req, State}. + ], Req, State}; +content_types_accepted(Req=#{qs := <<"wildcard-param">>}, State) -> + {[{{<<"text">>, <<"plain">>, '*'}, put_text_plain}], Req, State}. put_multipart_mixed(Req, State) -> {true, Req, State}. + +put_text_plain(Req0, State) -> + {ok, _, Req} = cowboy_req:read_body(Req0), + {true, Req, State}. diff --git a/test/handlers/content_types_provided_h.erl b/test/handlers/content_types_provided_h.erl new file mode 100644 index 0000000..5220c19 --- /dev/null +++ b/test/handlers/content_types_provided_h.erl @@ -0,0 +1,24 @@ +%% This module has different content_types_provided values +%% and/or sends a different response body depending on the +%% query string. + +-module(content_types_provided_h). + +-export([init/2]). +-export([content_types_provided/2]). +-export([get_text_plain/2]). + +init(Req, Opts) -> + {cowboy_rest, Req, Opts}. + +content_types_provided(Req=#{qs := <<"wildcard-param">>}, State) -> + {[{{<<"text">>, <<"plain">>, '*'}, get_text_plain}], Req, State}. + +get_text_plain(Req=#{qs := <<"wildcard-param">>}, State) -> + {_, _, Param} = maps:get(media_type, Req), + Body = if + Param =:= [] -> <<"[]">>; + Param =/= [] -> + iolist_to_binary([[Key, $=, Value] || {Key, Value} <- Param]) + end, + {Body, Req, State}. diff --git a/test/handlers/expires_h.erl b/test/handlers/expires_h.erl new file mode 100644 index 0000000..87fcb14 --- /dev/null +++ b/test/handlers/expires_h.erl @@ -0,0 +1,28 @@ +%% This module sends a different expires value +%% depending on the query string. + +-module(expires_h). + +-export([init/2]). +-export([content_types_provided/2]). +-export([get_text_plain/2]). +-export([expires/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}. + +expires(Req=#{qs := <<"tuple">>}, State) -> + {{{2012, 9, 21}, {22, 36, 14}}, Req, State}; +expires(Req=#{qs := <<"binary">>}, State) -> + {<<"0">>, Req, State}; +expires(Req=#{qs := <<"undefined">>}, State) -> + {undefined, Req, State}; +%% Simulate the callback being missing in other cases. +expires(#{qs := <<"missing">>}, _) -> + no_call. diff --git a/test/handlers/last_modified_h.erl b/test/handlers/last_modified_h.erl new file mode 100644 index 0000000..82893b3 --- /dev/null +++ b/test/handlers/last_modified_h.erl @@ -0,0 +1,24 @@ +%% This module sends a different last-modified value +%% depending on the query string. + +-module(last_modified_h). + +-export([init/2]). +-export([content_types_provided/2]). +-export([get_text_plain/2]). +-export([last_modified/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}. + +last_modified(Req=#{qs := <<"tuple">>}, State) -> + {{{2012, 9, 21}, {22, 36, 14}}, Req, State}; +%% Simulate the callback being missing in other cases. +last_modified(#{qs := <<"missing">>}, _) -> + no_call. |