diff options
author | Loïc Hoguin <[email protected]> | 2014-09-26 15:58:44 +0300 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2014-09-26 15:58:44 +0300 |
commit | 5ce4c2bfb40ecc4b687a2941e612025a1c4ff913 (patch) | |
tree | 7094d5f9d92c9c3bac1a60ca4b4922ba035b219d /test/http_SUITE_data | |
parent | fd37fad592fc96a384bcd060696194f5fe074f6f (diff) | |
download | cowboy-5ce4c2bfb40ecc4b687a2941e612025a1c4ff913.tar.gz cowboy-5ce4c2bfb40ecc4b687a2941e612025a1c4ff913.tar.bz2 cowboy-5ce4c2bfb40ecc4b687a2941e612025a1c4ff913.zip |
Unify the init and terminate callbacks
This set of changes is the first step to simplify the
writing of handlers, by removing some extraneous
callbacks and making others optional.
init/3 is now init/2, its first argument being removed.
rest_init/2 and rest_terminate/2 have been removed.
websocket_init/3 and websocket_terminate/3 have been removed.
terminate/3 is now optional. It is called regardless of
the type of handler, including rest and websocket.
The return value of init/2 changed. It now returns
{Mod, Req, Opts} with Mod being either one of the four
handler type or a custom module. It can also return extra
timeout and hibernate options.
The signature for sub protocols has changed, they now
receive these extra timeout and hibernate options.
Loop handlers are now implemented in cowboy_long_polling,
and will be renamed throughout the project in a future commit.
Diffstat (limited to 'test/http_SUITE_data')
25 files changed, 143 insertions, 149 deletions
diff --git a/test/http_SUITE_data/http_body_qs.erl b/test/http_SUITE_data/http_body_qs.erl index 09eebdb..b219566 100644 --- a/test/http_SUITE_data/http_body_qs.erl +++ b/test/http_SUITE_data/http_body_qs.erl @@ -1,11 +1,12 @@ %% Feel free to use, reuse and abuse the code in this file. -module(http_body_qs). --behaviour(cowboy_http_handler). --export([init/3, handle/2, terminate/3]). -init({_, http}, Req, _) -> - {ok, Req, undefined}. +-export([init/2]). +-export([handle/2]). + +init(Req, Opts) -> + {http, Req, Opts}. handle(Req, State) -> Method = cowboy_req:method(Req), @@ -33,6 +34,3 @@ echo(Echo, Req) -> cowboy_req:reply(200, [ {<<"content-type">>, <<"text/plain; charset=utf-8">>} ], Echo, Req). - -terminate(_, _, _) -> - ok. diff --git a/test/http_SUITE_data/http_chunked.erl b/test/http_SUITE_data/http_chunked.erl index 7f0d749..0c18363 100644 --- a/test/http_SUITE_data/http_chunked.erl +++ b/test/http_SUITE_data/http_chunked.erl @@ -1,11 +1,12 @@ %% Feel free to use, reuse and abuse the code in this file. -module(http_chunked). --behaviour(cowboy_http_handler). --export([init/3, handle/2, terminate/3]). -init({_Transport, http}, Req, _Opts) -> - {ok, Req, undefined}. +-export([init/2]). +-export([handle/2]). + +init(Req, Opts) -> + {http, Req, Opts}. handle(Req, State) -> Req2 = cowboy_req:chunked_reply(200, Req), @@ -14,6 +15,3 @@ handle(Req, State) -> timer:sleep(100), cowboy_req:chunk("works fine!", Req2), {ok, Req2, State}. - -terminate(_, _, _) -> - ok. diff --git a/test/http_SUITE_data/http_echo_body.erl b/test/http_SUITE_data/http_echo_body.erl index 986015a..8743844 100644 --- a/test/http_SUITE_data/http_echo_body.erl +++ b/test/http_SUITE_data/http_echo_body.erl @@ -1,11 +1,12 @@ %% Feel free to use, reuse and abuse the code in this file. -module(http_echo_body). --behaviour(cowboy_http_handler). --export([init/3, handle/2, terminate/3]). -init({_, http}, Req, _) -> - {ok, Req, undefined}. +-export([init/2]). +-export([handle/2]). + +init(Req, Opts) -> + {http, Req, Opts}. handle(Req, State) -> true = cowboy_req:has_body(Req), @@ -22,6 +23,3 @@ handle_body(Req, Body) -> Size = cowboy_req:body_length(Req), Size = byte_size(Body), cowboy_req:reply(200, [], Body, Req). - -terminate(_, _, _) -> - ok. diff --git a/test/http_SUITE_data/http_errors.erl b/test/http_SUITE_data/http_errors.erl index 7c3872b..39eda60 100644 --- a/test/http_SUITE_data/http_errors.erl +++ b/test/http_SUITE_data/http_errors.erl @@ -1,10 +1,11 @@ %% Feel free to use, reuse and abuse the code in this file. -module(http_errors). --behaviour(cowboy_http_handler). --export([init/3, handle/2, terminate/3]). -init({_Transport, http}, Req, _Opts) -> +-export([init/2]). +-export([handle/2]). + +init(Req, _Opts) -> #{'case' := Case} = cowboy_req:match_qs(Req, ['case']), case_init(Case, Req). @@ -17,11 +18,11 @@ case_init(<<"init_after_reply">> = Case, Req) -> error(Case); case_init(<<"init_reply_handle_error">> = Case, Req) -> Req1 = cowboy_req:reply(200, [], "http_handler_crashes", Req), - {ok, Req1, Case}; + {http, Req1, Case}; case_init(<<"handle_before_reply">> = Case, Req) -> - {ok, Req, Case}; + {http, Req, Case}; case_init(<<"handle_after_reply">> = Case, Req) -> - {ok, Req, Case}. + {http, Req, Case}. handle(_Req, <<"init_reply_handle_error">> = Case) -> cowboy_error_h:ignore(?MODULE, handle, 2), @@ -33,6 +34,3 @@ handle(Req, <<"handle_after_reply">> = Case) -> cowboy_error_h:ignore(?MODULE, handle, 2), _ = cowboy_req:reply(200, [], "http_handler_crashes", Req), error(Case). - -terminate(_, _, _) -> - ok. diff --git a/test/http_SUITE_data/http_handler.erl b/test/http_SUITE_data/http_handler.erl index 296c918..61c14f8 100644 --- a/test/http_SUITE_data/http_handler.erl +++ b/test/http_SUITE_data/http_handler.erl @@ -1,18 +1,14 @@ %% Feel free to use, reuse and abuse the code in this file. -module(http_handler). --behaviour(cowboy_http_handler). --export([init/3, handle/2, terminate/3]). --record(state, {headers, body}). +-export([init/2]). +-export([handle/2]). -init({_Transport, http}, Req, Opts) -> - Headers = proplists:get_value(headers, Opts, []), - Body = proplists:get_value(body, Opts, "http_handler"), - {ok, Req, #state{headers=Headers, body=Body}}. +init(Req, Opts) -> + {http, Req, Opts}. -handle(Req, State=#state{headers=Headers, body=Body}) -> +handle(Req, State) -> + Headers = proplists:get_value(headers, State, []), + Body = proplists:get_value(body, State, "http_handler"), {ok, cowboy_req:reply(200, Headers, Body, Req), State}. - -terminate(_, _, _) -> - ok. diff --git a/test/http_SUITE_data/http_init_shutdown.erl b/test/http_SUITE_data/http_init_shutdown.erl index 512132e..5aae898 100644 --- a/test/http_SUITE_data/http_init_shutdown.erl +++ b/test/http_SUITE_data/http_init_shutdown.erl @@ -1,17 +1,10 @@ %% Feel free to use, reuse and abuse the code in this file. -module(http_init_shutdown). --behaviour(cowboy_http_handler). --export([init/3, handle/2, terminate/3]). -init({_Transport, http}, Req, _Opts) -> +-export([init/2]). + +init(Req, _) -> Req2 = cowboy_req:reply(<<"666 Init Shutdown Testing">>, [{<<"connection">>, <<"close">>}], Req), {shutdown, Req2, undefined}. - -handle(Req, State) -> - Req2 = cowboy_req:reply(200, [], "Hello world!", Req), - {ok, Req2, State}. - -terminate(_, _, _) -> - ok. diff --git a/test/http_SUITE_data/http_loop_stream_recv.erl b/test/http_SUITE_data/http_loop_stream_recv.erl index 77a339b..8547cc9 100644 --- a/test/http_SUITE_data/http_loop_stream_recv.erl +++ b/test/http_SUITE_data/http_loop_stream_recv.erl @@ -1,14 +1,15 @@ %% Feel free to use, reuse and abuse the code in this file. -module(http_loop_stream_recv). --export([init/3]). + +-export([init/2]). -export([info/3]). -export([terminate/3]). -init({_, http}, Req, _) -> +init(Req, _) -> receive after 100 -> ok end, self() ! stream, - {loop, Req, undefined, 100}. + {long_polling, Req, undefined, 100}. info(stream, Req, undefined) -> stream(Req, 1, <<>>). diff --git a/test/http_SUITE_data/http_multipart.erl b/test/http_SUITE_data/http_multipart.erl index 43ff6ab..6bd6408 100644 --- a/test/http_SUITE_data/http_multipart.erl +++ b/test/http_SUITE_data/http_multipart.erl @@ -1,19 +1,17 @@ %% Feel free to use, reuse and abuse the code in this file. -module(http_multipart). --behaviour(cowboy_http_handler). --export([init/3, handle/2, terminate/3]). -init({_Transport, http}, Req, []) -> - {ok, Req, {}}. +-export([init/2]). +-export([handle/2]). + +init(Req, Opts) -> + {http, Req, Opts}. handle(Req, State) -> {Result, Req2} = acc_multipart(Req, []), {ok, cowboy_req:reply(200, [], term_to_binary(Result), Req2), State}. -terminate(_, _, _) -> - ok. - acc_multipart(Req, Acc) -> case cowboy_req:part(Req) of {ok, Headers, Req2} -> diff --git a/test/http_SUITE_data/http_multipart_stream.erl b/test/http_SUITE_data/http_multipart_stream.erl index bde7531..43d459a 100644 --- a/test/http_SUITE_data/http_multipart_stream.erl +++ b/test/http_SUITE_data/http_multipart_stream.erl @@ -1,19 +1,17 @@ %% Feel free to use, reuse and abuse the code in this file. -module(http_multipart_stream). --behaviour(cowboy_http_handler). --export([init/3, handle/2, terminate/3]). -init(_, Req, []) -> - {ok, Req, undefined}. +-export([init/2]). +-export([handle/2]). + +init(Req, Opts) -> + {http, Req, Opts}. handle(Req, State) -> Req2 = multipart(Req), {ok, cowboy_req:reply(200, Req2), State}. -terminate(_, _, _) -> - ok. - multipart(Req) -> case cowboy_req:part(Req) of {ok, [{<<"content-length">>, BinLength}], Req2} -> diff --git a/test/http_SUITE_data/http_req_attr.erl b/test/http_SUITE_data/http_req_attr.erl index 2a4a55d..9c5acba 100644 --- a/test/http_SUITE_data/http_req_attr.erl +++ b/test/http_SUITE_data/http_req_attr.erl @@ -1,18 +1,19 @@ %% Feel free to use, reuse and abuse the code in this file. +%% @todo That module was clearly meant to do more than one +%% thing and yet doesn't. -module(http_req_attr). --behaviour(cowboy_http_handler). --export([init/3, handle/2, terminate/3]). -init({_, http}, Req, _) -> - #{attr := Attr} = cowboy_req:match_qs(Req, [attr]), - {ok, Req, Attr}. +-export([init/2]). +-export([handle/2]). + +init(Req, Opts) -> + {http, Req, Opts}. -handle(Req, <<"host_and_port">> = Attr) -> +handle(Req, State) -> + #{attr := Attr} = cowboy_req:match_qs(Req, [attr]), + <<"host_and_port">> = Attr, Host = cowboy_req:host(Req), Port = cowboy_req:port(Req), Value = [Host, "\n", integer_to_list(Port)], - {ok, cowboy_req:reply(200, [], Value, Req), Attr}. - -terminate(_, _, _) -> - ok. + {ok, cowboy_req:reply(200, [], Value, Req), State}. diff --git a/test/http_SUITE_data/http_set_resp.erl b/test/http_SUITE_data/http_set_resp.erl index 628f745..77196a8 100644 --- a/test/http_SUITE_data/http_set_resp.erl +++ b/test/http_SUITE_data/http_set_resp.erl @@ -1,10 +1,11 @@ %% Feel free to use, reuse and abuse the code in this file. -module(http_set_resp). --behaviour(cowboy_http_handler). --export([init/3, handle/2, terminate/3]). -init({_Transport, http}, Req, Opts) -> +-export([init/2]). +-export([handle/2]). + +init(Req, Opts) -> Headers = proplists:get_value(headers, Opts, []), Body = proplists:get_value(body, Opts, <<"http_handler_set_resp">>), Req2 = lists:foldl(fun({Name, Value}, R) -> @@ -13,7 +14,7 @@ init({_Transport, http}, Req, Opts) -> Req3 = cowboy_req:set_resp_body(Body, Req2), Req4 = cowboy_req:set_resp_header(<<"x-cowboy-test">>, <<"ok">>, Req3), Req5 = cowboy_req:set_resp_cookie(<<"cake">>, <<"lie">>, [], Req4), - {ok, Req5, undefined}. + {http, Req5, undefined}. handle(Req, State) -> case cowboy_req:has_resp_header(<<"x-cowboy-test">>, Req) of @@ -26,6 +27,3 @@ handle(Req, State) -> {ok, cowboy_req:reply(200, Req), State} end end. - -terminate(_, _, _) -> - ok. diff --git a/test/http_SUITE_data/http_stream_body.erl b/test/http_SUITE_data/http_stream_body.erl index 9be79a1..29569cd 100644 --- a/test/http_SUITE_data/http_stream_body.erl +++ b/test/http_SUITE_data/http_stream_body.erl @@ -1,18 +1,16 @@ %% Feel free to use, reuse and abuse the code in this file. -module(http_stream_body). --behaviour(cowboy_http_handler). --export([init/3, handle/2, terminate/3]). --record(state, {headers, body, reply}). +-export([init/2]). +-export([handle/2]). -init({_Transport, http}, Req, Opts) -> - Headers = proplists:get_value(headers, Opts, []), - Body = proplists:get_value(body, Opts, "http_handler_stream_body"), - Reply = proplists:get_value(reply, Opts), - {ok, Req, #state{headers=Headers, body=Body, reply=Reply}}. +init(Req, Opts) -> + {http, Req, Opts}. -handle(Req, State=#state{headers=_Headers, body=Body, reply=Reply}) -> +handle(Req, State) -> + Body = proplists:get_value(body, State, "http_handler_stream_body"), + Reply = proplists:get_value(reply, State), SFun = fun(Socket, Transport) -> Transport:send(Socket, Body) end, Req2 = case Reply of set_resp -> @@ -26,6 +24,3 @@ handle(Req, State=#state{headers=_Headers, body=Body, reply=Reply}) -> cowboy_req:set_resp_body_fun(chunked, SFun2, Req) end, {ok, cowboy_req:reply(200, Req2), State}. - -terminate(_, _, _) -> - ok. diff --git a/test/http_SUITE_data/http_streamed.erl b/test/http_SUITE_data/http_streamed.erl index 5f90077..ba710f1 100644 --- a/test/http_SUITE_data/http_streamed.erl +++ b/test/http_SUITE_data/http_streamed.erl @@ -1,11 +1,12 @@ %% Feel free to use, reuse and abuse the code in this file. -module(http_streamed). --behaviour(cowboy_http_handler). --export([init/3, handle/2, terminate/3]). -init({_Transport, http}, Req, _Opts) -> - {ok, Req, undefined}. +-export([init/2]). +-export([handle/2]). + +init(Req, Opts) -> + {http, Req, Opts}. handle(Req, State) -> Req2 = cowboy_req:set([{resp_state, waiting_stream}], Req), @@ -15,6 +16,3 @@ handle(Req, State) -> timer:sleep(100), cowboy_req:chunk("works fine!", Req3), {ok, Req3, State}. - -terminate(_, _, _) -> - ok. diff --git a/test/http_SUITE_data/rest_empty_resource.erl b/test/http_SUITE_data/rest_empty_resource.erl index 7e7c00a..97fc26f 100644 --- a/test/http_SUITE_data/rest_empty_resource.erl +++ b/test/http_SUITE_data/rest_empty_resource.erl @@ -1,5 +1,6 @@ -module(rest_empty_resource). --export([init/3]). -init(_Transport, _Req, _Opts) -> - {upgrade, protocol, cowboy_rest}. +-export([init/2]). + +init(Req, Opts) -> + {rest, Req, Opts}. diff --git a/test/http_SUITE_data/rest_expires.erl b/test/http_SUITE_data/rest_expires.erl index 4209041..e71b107 100644 --- a/test/http_SUITE_data/rest_expires.erl +++ b/test/http_SUITE_data/rest_expires.erl @@ -1,13 +1,13 @@ -module(rest_expires). --export([init/3]). +-export([init/2]). -export([content_types_provided/2]). -export([get_text_plain/2]). -export([expires/2]). -export([last_modified/2]). -init(_Transport, _Req, _Opts) -> - {upgrade, protocol, cowboy_rest}. +init(Req, Opts) -> + {rest, Req, Opts}. content_types_provided(Req, State) -> {[{{<<"text">>, <<"plain">>, []}, get_text_plain}], Req, State}. diff --git a/test/http_SUITE_data/rest_expires_binary.erl b/test/http_SUITE_data/rest_expires_binary.erl index 4cbd001..84b0675 100644 --- a/test/http_SUITE_data/rest_expires_binary.erl +++ b/test/http_SUITE_data/rest_expires_binary.erl @@ -1,12 +1,12 @@ -module(rest_expires_binary). --export([init/3]). +-export([init/2]). -export([content_types_provided/2]). -export([get_text_plain/2]). -export([expires/2]). -init(_Transport, _Req, _Opts) -> - {upgrade, protocol, cowboy_rest}. +init(Req, Opts) -> + {rest, Req, Opts}. content_types_provided(Req, State) -> {[{{<<"text">>, <<"plain">>, []}, get_text_plain}], Req, State}. diff --git a/test/http_SUITE_data/rest_forbidden_resource.erl b/test/http_SUITE_data/rest_forbidden_resource.erl index d055193..1e6d99f 100644 --- a/test/http_SUITE_data/rest_forbidden_resource.erl +++ b/test/http_SUITE_data/rest_forbidden_resource.erl @@ -1,13 +1,15 @@ -module(rest_forbidden_resource). --export([init/3, rest_init/2, allowed_methods/2, forbidden/2, - content_types_provided/2, content_types_accepted/2, - to_text/2, from_text/2]). -init(_Transport, _Req, _Opts) -> - {upgrade, protocol, cowboy_rest}. +-export([init/2]). +-export([allowed_methods/2]). +-export([forbidden/2]). +-export([content_types_provided/2]). +-export([content_types_accepted/2]). +-export([to_text/2]). +-export([from_text/2]). -rest_init(Req, [Forbidden]) -> - {ok, Req, Forbidden}. +init(Req, [Forbidden]) -> + {rest, Req, Forbidden}. allowed_methods(Req, State) -> {[<<"GET">>, <<"HEAD">>, <<"POST">>], Req, State}. diff --git a/test/http_SUITE_data/rest_missing_callbacks.erl b/test/http_SUITE_data/rest_missing_callbacks.erl index 94bfbbd..fec308a 100644 --- a/test/http_SUITE_data/rest_missing_callbacks.erl +++ b/test/http_SUITE_data/rest_missing_callbacks.erl @@ -1,11 +1,12 @@ -module(rest_missing_callbacks). --export([init/3]). + +-export([init/2]). -export([allowed_methods/2]). -export([content_types_accepted/2]). -export([content_types_provided/2]). -init(_Transport, _Req, _Opts) -> - {upgrade, protocol, cowboy_rest}. +init(Req, Opts) -> + {rest, Req, Opts}. allowed_methods(Req, State) -> {[<<"GET">>, <<"PUT">>], Req, State}. diff --git a/test/http_SUITE_data/rest_nodelete_resource.erl b/test/http_SUITE_data/rest_nodelete_resource.erl index 9f9670c..e8123db 100644 --- a/test/http_SUITE_data/rest_nodelete_resource.erl +++ b/test/http_SUITE_data/rest_nodelete_resource.erl @@ -1,17 +1,18 @@ -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_rest}. +-export([init/2]). +-export([allowed_methods/2]). +-export([content_types_provided/2]). +-export([get_text_plain/2]). + +init(Req, Opts) -> + {rest, Req, Opts}. 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}. - diff --git a/test/http_SUITE_data/rest_param_all.erl b/test/http_SUITE_data/rest_param_all.erl index 22daac7..54950eb 100644 --- a/test/http_SUITE_data/rest_param_all.erl +++ b/test/http_SUITE_data/rest_param_all.erl @@ -1,14 +1,14 @@ -module(rest_param_all). --export([init/3]). +-export([init/2]). -export([allowed_methods/2]). -export([content_types_provided/2]). -export([get_text_plain/2]). -export([content_types_accepted/2]). -export([put_text_plain/2]). -init(_Transport, _Req, _Opts) -> - {upgrade, protocol, cowboy_rest}. +init(Req, Opts) -> + {rest, Req, Opts}. allowed_methods(Req, State) -> {[<<"GET">>, <<"PUT">>], Req, State}. diff --git a/test/http_SUITE_data/rest_patch_resource.erl b/test/http_SUITE_data/rest_patch_resource.erl index 7b9b76e..4b81648 100644 --- a/test/http_SUITE_data/rest_patch_resource.erl +++ b/test/http_SUITE_data/rest_patch_resource.erl @@ -1,9 +1,14 @@ -module(rest_patch_resource). --export([init/3, allowed_methods/2, content_types_provided/2, get_text_plain/2, - content_types_accepted/2, patch_text_plain/2]). -init(_Transport, _Req, _Opts) -> - {upgrade, protocol, cowboy_rest}. +-export([init/2]). +-export([allowed_methods/2]). +-export([content_types_provided/2]). +-export([get_text_plain/2]). +-export([content_types_accepted/2]). +-export([patch_text_plain/2]). + +init(Req, Opts) -> + {rest, Req, Opts}. allowed_methods(Req, State) -> {[<<"HEAD">>, <<"GET">>, <<"PATCH">>], Req, State}. diff --git a/test/http_SUITE_data/rest_post_charset_resource.erl b/test/http_SUITE_data/rest_post_charset_resource.erl index 9ccfa61..7b7c49c 100644 --- a/test/http_SUITE_data/rest_post_charset_resource.erl +++ b/test/http_SUITE_data/rest_post_charset_resource.erl @@ -1,8 +1,12 @@ -module(rest_post_charset_resource). --export([init/3, allowed_methods/2, content_types_accepted/2, from_text/2]). -init(_Transport, _Req, _Opts) -> - {upgrade, protocol, cowboy_rest}. +-export([init/2]). +-export([allowed_methods/2]). +-export([content_types_accepted/2]). +-export([from_text/2]). + +init(Req, Opts) -> + {rest, Req, Opts}. allowed_methods(Req, State) -> {[<<"POST">>], Req, State}. diff --git a/test/http_SUITE_data/rest_postonly_resource.erl b/test/http_SUITE_data/rest_postonly_resource.erl index 4f725c9..9b14b24 100644 --- a/test/http_SUITE_data/rest_postonly_resource.erl +++ b/test/http_SUITE_data/rest_postonly_resource.erl @@ -1,8 +1,12 @@ -module(rest_postonly_resource). --export([init/3, allowed_methods/2, content_types_accepted/2, from_text/2]). -init(_Transport, _Req, _Opts) -> - {upgrade, protocol, cowboy_rest}. +-export([init/2]). +-export([allowed_methods/2]). +-export([content_types_accepted/2]). +-export([from_text/2]). + +init(Req, Opts) -> + {rest, Req, Opts}. allowed_methods(Req, State) -> {[<<"POST">>], Req, State}. diff --git a/test/http_SUITE_data/rest_resource_etags.erl b/test/http_SUITE_data/rest_resource_etags.erl index fb266d1..9509d0a 100644 --- a/test/http_SUITE_data/rest_resource_etags.erl +++ b/test/http_SUITE_data/rest_resource_etags.erl @@ -1,8 +1,12 @@ -module(rest_resource_etags). --export([init/3, generate_etag/2, content_types_provided/2, get_text_plain/2]). -init(_Transport, _Req, _Opts) -> - {upgrade, protocol, cowboy_rest}. +-export([init/2]). +-export([generate_etag/2]). +-export([content_types_provided/2]). +-export([get_text_plain/2]). + +init(Req, Opts) -> + {rest, Req, Opts}. generate_etag(Req, State) -> #{type := Type} = cowboy_req:match_qs(Req, [type]), diff --git a/test/http_SUITE_data/rest_simple_resource.erl b/test/http_SUITE_data/rest_simple_resource.erl index 97145dd..3d2787f 100644 --- a/test/http_SUITE_data/rest_simple_resource.erl +++ b/test/http_SUITE_data/rest_simple_resource.erl @@ -1,12 +1,14 @@ -module(rest_simple_resource). --export([init/3, content_types_provided/2, get_text_plain/2]). -init(_Transport, _Req, _Opts) -> - {upgrade, protocol, cowboy_rest}. +-export([init/2]). +-export([content_types_provided/2]). +-export([get_text_plain/2]). + +init(Req, Opts) -> + {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}. - |