diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/cowboy_test.erl | 51 | ||||
-rw-r--r-- | test/handlers/asterisk_h.erl | 2 | ||||
-rw-r--r-- | test/handlers/echo_h.erl | 2 | ||||
-rw-r--r-- | test/handlers/hello_h.erl | 2 | ||||
-rw-r--r-- | test/handlers/loop_handler_body_h.erl | 5 | ||||
-rw-r--r-- | test/http_SUITE.erl | 70 | ||||
-rw-r--r-- | test/http_SUITE_data/http_body_qs.erl | 12 | ||||
-rw-r--r-- | test/http_SUITE_data/http_echo_body.erl | 6 | ||||
-rw-r--r-- | test/http_SUITE_data/http_errors.erl | 2 | ||||
-rw-r--r-- | test/http_SUITE_data/http_handler.erl | 2 | ||||
-rw-r--r-- | test/http_SUITE_data/http_multipart.erl | 2 | ||||
-rw-r--r-- | test/http_SUITE_data/http_req_attr.erl | 2 | ||||
-rw-r--r-- | test/http_SUITE_data/http_set_resp.erl | 4 | ||||
-rw-r--r-- | test/http_SUITE_data/http_stream_body.erl | 16 | ||||
-rw-r--r-- | test/http_SUITE_data/rest_param_all.erl | 2 | ||||
-rw-r--r-- | test/http_SUITE_data/rest_patch_resource.erl | 2 | ||||
-rw-r--r-- | test/rfc7230_SUITE.erl | 24 | ||||
-rw-r--r-- | test/ws_SUITE.erl | 16 | ||||
-rw-r--r-- | test/ws_SUITE_data/ws_echo_timer.erl | 6 | ||||
-rw-r--r-- | test/ws_SUITE_data/ws_send_many.erl | 6 |
20 files changed, 121 insertions, 113 deletions
diff --git a/test/cowboy_test.erl b/test/cowboy_test.erl index cced1f9..e3aeb97 100644 --- a/test/cowboy_test.erl +++ b/test/cowboy_test.erl @@ -20,21 +20,21 @@ %% Listeners initialization. init_http(Ref, ProtoOpts, Config) -> - {ok, _} = cowboy:start_http(Ref, 100, [{port, 0}], ProtoOpts), + {ok, _} = cowboy:start_clear(Ref, 100, [{port, 0}], ProtoOpts), Port = ranch:get_port(Ref), - [{type, tcp}, {port, Port}, {opts, []}|Config]. + [{type, tcp}, {protocol, http}, {port, Port}, {opts, []}|Config]. init_https(Ref, ProtoOpts, Config) -> Opts = ct_helper:get_certs_from_ets(), - {ok, _} = cowboy:start_https(Ref, 100, Opts ++ [{port, 0}], ProtoOpts), + {ok, _} = cowboy:start_tls(Ref, 100, Opts ++ [{port, 0}], ProtoOpts), Port = ranch:get_port(Ref), - [{type, ssl}, {port, Port}, {opts, Opts}|Config]. + [{type, ssl}, {protocol, http}, {port, Port}, {opts, Opts}|Config]. init_spdy(Ref, ProtoOpts, Config) -> Opts = ct_helper:get_certs_from_ets(), - {ok, _} = cowboy:start_spdy(Ref, 100, Opts ++ [{port, 0}], ProtoOpts), + {ok, _} = cowboy:start_tls(Ref, 100, Opts ++ [{port, 0}], ProtoOpts), Port = ranch:get_port(Ref), - [{type, ssl}, {port, Port}, {opts, Opts}|Config]. + [{type, ssl}, {protocol, spdy}, {port, Port}, {opts, Opts}|Config]. %% Common group of listeners used by most suites. @@ -59,32 +59,26 @@ common_groups(Tests) -> ]. init_common_groups(Name = http, Config, Mod) -> - init_http(Name, [ - {env, [{dispatch, Mod:init_dispatch(Config)}]} - ], Config); + init_http(Name, #{env => #{dispatch => Mod:init_dispatch(Config)}}, Config); init_common_groups(Name = https, Config, Mod) -> - init_https(Name, [ - {env, [{dispatch, Mod:init_dispatch(Config)}]} - ], Config); + init_https(Name, #{env => #{dispatch => Mod:init_dispatch(Config)}}, Config); init_common_groups(Name = spdy, Config, Mod) -> - init_spdy(Name, [ - {env, [{dispatch, Mod:init_dispatch(Config)}]} - ], Config); + init_https(Name, #{env => #{dispatch => Mod:init_dispatch(Config)}}, Config); init_common_groups(Name = http_compress, Config, Mod) -> - init_http(Name, [ - {env, [{dispatch, Mod:init_dispatch(Config)}]}, - {compress, true} - ], Config); + init_http(Name, #{ + env => #{dispatch => Mod:init_dispatch(Config)}, + compress => true + }, Config); init_common_groups(Name = https_compress, Config, Mod) -> - init_https(Name, [ - {env, [{dispatch, Mod:init_dispatch(Config)}]}, - {compress, true} - ], Config); + init_https(Name, #{ + env => #{dispatch => Mod:init_dispatch(Config)}, + compress => true + }, Config); init_common_groups(Name = spdy_compress, Config, Mod) -> - init_spdy(Name, [ - {env, [{dispatch, Mod:init_dispatch(Config)}]}, - {compress, true} - ], Config). + init_spdy(Name, #{ + env => #{dispatch => Mod:init_dispatch(Config)}, + compress => true + }, Config). %% Support functions for testing using Gun. @@ -94,7 +88,8 @@ gun_open(Config) -> gun_open(Config, Opts) -> {ok, ConnPid} = gun:open("localhost", config(port, Config), Opts#{ retry => 0, - transport => config(type, Config) + transport => config(type, Config), + protocols => [config(protocol, Config)] }), ConnPid. diff --git a/test/handlers/asterisk_h.erl b/test/handlers/asterisk_h.erl index b5ff32d..56b8bcb 100644 --- a/test/handlers/asterisk_h.erl +++ b/test/handlers/asterisk_h.erl @@ -13,4 +13,4 @@ echo(What, Req, Opts) -> V when is_integer(V) -> integer_to_binary(V); V -> V end, - {ok, cowboy_req:reply(200, [], Value, Req), Opts}. + {ok, cowboy_req:reply(200, #{}, Value, Req), Opts}. diff --git a/test/handlers/echo_h.erl b/test/handlers/echo_h.erl index 71408c3..6db43fe 100644 --- a/test/handlers/echo_h.erl +++ b/test/handlers/echo_h.erl @@ -13,4 +13,4 @@ echo(What, Req, Opts) -> V when is_integer(V) -> integer_to_binary(V); V -> V end, - {ok, cowboy_req:reply(200, [], Value, Req), Opts}. + {ok, cowboy_req:reply(200, #{}, Value, Req), Opts}. diff --git a/test/handlers/hello_h.erl b/test/handlers/hello_h.erl index 3be7b6d..5e3dcc8 100644 --- a/test/handlers/hello_h.erl +++ b/test/handlers/hello_h.erl @@ -5,4 +5,4 @@ -export([init/2]). init(Req, Opts) -> - {ok, cowboy_req:reply(200, [], <<"Hello world!">>, Req), Opts}. + {ok, cowboy_req:reply(200, #{}, <<"Hello world!">>, Req), Opts}. diff --git a/test/handlers/loop_handler_body_h.erl b/test/handlers/loop_handler_body_h.erl index 0d4fd4d..38ba2c0 100644 --- a/test/handlers/loop_handler_body_h.erl +++ b/test/handlers/loop_handler_body_h.erl @@ -14,9 +14,10 @@ init(Req, _) -> {cowboy_loop, Req, undefined, 5000, hibernate}. info(timeout, Req, State) -> - {ok, Body, Req2} = cowboy_req:body(Req), + {ok, Body, Req2} = cowboy_req:read_body(Req), 100000 = byte_size(Body), - {stop, cowboy_req:reply(200, Req2), State}. + cowboy_req:reply(200, Req2), + {stop, Req, State}. terminate(stop, _, _) -> ok. diff --git a/test/http_SUITE.erl b/test/http_SUITE.erl index d5ec909..1b39feb 100644 --- a/test/http_SUITE.erl +++ b/test/http_SUITE.erl @@ -45,7 +45,7 @@ groups() -> parse_host, set_env_dispatch ], [ - {http, [parallel], Tests}, + {http, [], Tests}, %% @todo parallel {https, [parallel], Tests}, {http_compress, [parallel], Tests}, {https_compress, [parallel], Tests}, @@ -73,33 +73,29 @@ end_per_suite(Config) -> ct_helper:delete_static_dir(config(static_dir, Config)). init_per_group(Name = http, Config) -> - cowboy_test:init_http(Name, [ - {env, [{dispatch, init_dispatch(Config)}]} - ], Config); + cowboy_test:init_http(Name, #{env => #{dispatch => init_dispatch(Config)}}, Config); init_per_group(Name = https, Config) -> - cowboy_test:init_https(Name, [ - {env, [{dispatch, init_dispatch(Config)}]} - ], Config); + cowboy_test:init_https(Name, #{env => #{dispatch => init_dispatch(Config)}}, Config); init_per_group(Name = http_compress, Config) -> - cowboy_test:init_http(Name, [ - {env, [{dispatch, init_dispatch(Config)}]}, - {compress, true} - ], Config); + cowboy_test:init_http(Name, #{ + env => #{dispatch => init_dispatch(Config)}, + compress => true + }, Config); init_per_group(Name = https_compress, Config) -> - cowboy_test:init_https(Name, [ - {env, [{dispatch, init_dispatch(Config)}]}, - {compress, true} - ], Config); + cowboy_test:init_https(Name, #{ + env => #{dispatch => init_dispatch(Config)}, + compress => true + }, Config); %% Most, if not all of these, should be in separate test suites. init_per_group(onresponse, Config) -> - {ok, _} = cowboy:start_http(onresponse, 100, [{port, 0}], [ + {ok, _} = cowboy:start_clear(onresponse, 100, [{port, 0}], [ {env, [{dispatch, init_dispatch(Config)}]}, {onresponse, fun do_onresponse_hook/4} ]), Port = ranch:get_port(onresponse), [{type, tcp}, {port, Port}, {opts, []}|Config]; init_per_group(onresponse_capitalize, Config) -> - {ok, _} = cowboy:start_http(onresponse_capitalize, 100, [{port, 0}], [ + {ok, _} = cowboy:start_clear(onresponse_capitalize, 100, [{port, 0}], [ {env, [{dispatch, init_dispatch(Config)}]}, {onresponse, fun do_onresponse_capitalize_hook/4} ]), @@ -111,13 +107,13 @@ init_per_group(parse_host, Config) -> {"/req_attr", http_req_attr, []} ]} ]), - {ok, _} = cowboy:start_http(parse_host, 100, [{port, 0}], [ + {ok, _} = cowboy:start_clear(parse_host, 100, [{port, 0}], [ {env, [{dispatch, Dispatch}]} ]), Port = ranch:get_port(parse_host), [{type, tcp}, {port, Port}, {opts, []}|Config]; init_per_group(set_env, Config) -> - {ok, _} = cowboy:start_http(set_env, 100, [{port, 0}], [ + {ok, _} = cowboy:start_clear(set_env, 100, [{port, 0}], [ {env, [{dispatch, []}]} ]), Port = ranch:get_port(set_env), @@ -134,11 +130,11 @@ init_dispatch(Config) -> {"/chunked_response", http_chunked, []}, {"/streamed_response", http_streamed, []}, {"/headers/dupe", http_handler, - [{headers, [{<<"connection">>, <<"close">>}]}]}, + [{headers, #{<<"connection">> => <<"close">>}}]}, {"/set_resp/header", http_set_resp, - [{headers, [{<<"vary">>, <<"Accept">>}]}]}, + [{headers, #{<<"vary">> => <<"Accept">>}}]}, {"/set_resp/overwrite", http_set_resp, - [{headers, [{<<"server">>, <<"DesireDrive/1.0">>}]}]}, + [{headers, #{<<"server">> => <<"DesireDrive/1.0">>}}]}, {"/set_resp/body", http_set_resp, [{body, <<"A flameless dance does not equal a cycle">>}]}, {"/stream_body/set_resp", http_stream_body, @@ -314,7 +310,7 @@ echo_body(Config) -> %% Check if sending request whose size is bigger than 1000000 bytes causes 413 echo_body_max_length(Config) -> ConnPid = gun_open(Config), - Ref = gun:post(ConnPid, "/echo/body", [], << 0:2000000/unit:8 >>), + Ref = gun:post(ConnPid, "/echo/body", [], << 0:10000000/unit:8 >>), {response, nofin, 413, _} = gun:await(ConnPid, Ref), ok. @@ -336,7 +332,7 @@ error_init_after_reply(Config) -> ConnPid = gun_open(Config), Ref = gun:get(ConnPid, "/handler_errors?case=init_after_reply"), {response, nofin, 200, _} = gun:await(ConnPid, Ref), - gun_down(ConnPid). + ok. headers_dupe(Config) -> ConnPid = gun_open(Config), @@ -357,18 +353,18 @@ http10_chunkless(Config) -> http10_hostless(Config) -> Name = http10_hostless, Port10 = config(port, Config) + 10, - Transport = case config(type, Config) of - tcp -> ranch_tcp; - ssl -> ranch_ssl + {Transport, Protocol} = case config(type, Config) of + tcp -> {ranch_tcp, cowboy_clear}; + ssl -> {ranch_ssl, cowboy_tls} end, ranch:start_listener(Name, 5, Transport, config(opts, Config) ++ [{port, Port10}], - cowboy_protocol, [ - {env, [{dispatch, cowboy_router:compile([ - {'_', [{"/http1.0/hostless", http_handler, []}]}])}]}, - {max_keepalive, 50}, - {timeout, 500}] - ), + Protocol, #{ + env =>#{dispatch => cowboy_router:compile([ + {'_', [{"/http1.0/hostless", http_handler, []}]}])}, + max_keepalive => 50, + timeout => 500 + }), 200 = do_raw("GET /http1.0/hostless HTTP/1.0\r\n\r\n", [{port, Port10}|Config]), cowboy:stop_listener(http10_hostless). @@ -380,9 +376,10 @@ http10_keepalive_default(Config) -> case catch raw_recv_head(Client) of {'EXIT', _} -> error(closed); Data -> - {'HTTP/1.0', 200, _, Rest} = cow_http:parse_status_line(Data), + %% Cowboy always advertises itself as HTTP/1.1. + {'HTTP/1.1', 200, _, Rest} = cow_http:parse_status_line(Data), {Headers, _} = cow_http:parse_headers(Rest), - false = lists:keymember(<<"connection">>, 1, Headers) + {_, <<"close">>} = lists:keyfind(<<"connection">>, 1, Headers) end, ok = raw_send(Client, Normal), case catch raw_recv_head(Client) of @@ -397,7 +394,8 @@ http10_keepalive_forced(Config) -> case catch raw_recv_head(Client) of {'EXIT', _} -> error(closed); Data -> - {'HTTP/1.0', 200, _, Rest} = cow_http:parse_status_line(Data), + %% Cowboy always advertises itself as HTTP/1.1. + {'HTTP/1.1', 200, _, Rest} = cow_http:parse_status_line(Data), {Headers, _} = cow_http:parse_headers(Rest), {_, <<"keep-alive">>} = lists:keyfind(<<"connection">>, 1, Headers) end, diff --git a/test/http_SUITE_data/http_body_qs.erl b/test/http_SUITE_data/http_body_qs.erl index 945b7fd..e0673cf 100644 --- a/test/http_SUITE_data/http_body_qs.erl +++ b/test/http_SUITE_data/http_body_qs.erl @@ -17,16 +17,16 @@ maybe_echo(<<"POST">>, true, Req) -> echo(proplists:get_value(<<"echo">>, PostVals), Req2) end; maybe_echo(<<"POST">>, false, Req) -> - cowboy_req:reply(400, [], <<"Missing body.">>, Req); + cowboy_req:reply(400, #{}, <<"Missing body.">>, Req); maybe_echo(_, _, Req) -> %% Method not allowed. cowboy_req:reply(405, Req). echo(badlength, Req) -> - cowboy_req:reply(413, [], <<"POST body bigger than 16000 bytes">>, Req); + cowboy_req:reply(413, #{}, <<"POST body bigger than 16000 bytes">>, Req); echo(undefined, Req) -> - cowboy_req:reply(400, [], <<"Missing echo parameter.">>, Req); + cowboy_req:reply(400, #{}, <<"Missing echo parameter.">>, Req); echo(Echo, Req) -> - cowboy_req:reply(200, [ - {<<"content-type">>, <<"text/plain; charset=utf-8">>} - ], Echo, Req). + cowboy_req:reply(200, #{ + <<"content-type">> => <<"text/plain; charset=utf-8">> + }, Echo, Req). diff --git a/test/http_SUITE_data/http_echo_body.erl b/test/http_SUITE_data/http_echo_body.erl index c76b9b3..a541a67 100644 --- a/test/http_SUITE_data/http_echo_body.erl +++ b/test/http_SUITE_data/http_echo_body.erl @@ -6,16 +6,16 @@ init(Req, Opts) -> true = cowboy_req:has_body(Req), - Req3 = case cowboy_req:body(Req, [{length, 1000000}]) of + Req3 = case cowboy_req:read_body(Req, [{length, 1000000}]) of {ok, Body, Req2} -> handle_body(Req2, Body); {more, _, Req2} -> handle_badlength(Req2) end, {ok, Req3, Opts}. handle_badlength(Req) -> - cowboy_req:reply(413, [], <<"Request entity too large">>, Req). + cowboy_req:reply(413, #{}, <<"Request entity too large">>, Req). handle_body(Req, Body) -> Size = cowboy_req:body_length(Req), Size = byte_size(Body), - cowboy_req:reply(200, [], Body, Req). + cowboy_req:reply(200, #{}, Body, Req). diff --git a/test/http_SUITE_data/http_errors.erl b/test/http_SUITE_data/http_errors.erl index ee5c2b2..14e3d09 100644 --- a/test/http_SUITE_data/http_errors.erl +++ b/test/http_SUITE_data/http_errors.erl @@ -13,5 +13,5 @@ case_init(<<"init_before_reply">> = Case, _Req) -> error(Case); case_init(<<"init_after_reply">> = Case, Req) -> ct_helper_error_h:ignore(?MODULE, case_init, 2), - _ = cowboy_req:reply(200, [], "http_handler_crashes", Req), + _ = cowboy_req:reply(200, #{}, "http_handler_crashes", Req), error(Case). diff --git a/test/http_SUITE_data/http_handler.erl b/test/http_SUITE_data/http_handler.erl index 62e9193..eb31aa8 100644 --- a/test/http_SUITE_data/http_handler.erl +++ b/test/http_SUITE_data/http_handler.erl @@ -5,6 +5,6 @@ -export([init/2]). init(Req, Opts) -> - Headers = proplists:get_value(headers, Opts, []), + Headers = proplists:get_value(headers, Opts, #{}), Body = proplists:get_value(body, Opts, "http_handler"), {ok, cowboy_req:reply(200, Headers, Body, Req), Opts}. diff --git a/test/http_SUITE_data/http_multipart.erl b/test/http_SUITE_data/http_multipart.erl index 196cbce..212f569 100644 --- a/test/http_SUITE_data/http_multipart.erl +++ b/test/http_SUITE_data/http_multipart.erl @@ -6,7 +6,7 @@ init(Req, Opts) -> {Result, Req2} = acc_multipart(Req, []), - {ok, cowboy_req:reply(200, [], term_to_binary(Result), Req2), Opts}. + {ok, cowboy_req:reply(200, #{}, term_to_binary(Result), Req2), Opts}. acc_multipart(Req, Acc) -> case cowboy_req:part(Req) of diff --git a/test/http_SUITE_data/http_req_attr.erl b/test/http_SUITE_data/http_req_attr.erl index d8483a5..c6a940e 100644 --- a/test/http_SUITE_data/http_req_attr.erl +++ b/test/http_SUITE_data/http_req_attr.erl @@ -12,4 +12,4 @@ init(Req, Opts) -> Host = cowboy_req:host(Req), Port = cowboy_req:port(Req), Value = [Host, "\n", integer_to_list(Port)], - {ok, cowboy_req:reply(200, [], Value, Req), Opts}. + {ok, cowboy_req:reply(200, #{}, Value, Req), Opts}. diff --git a/test/http_SUITE_data/http_set_resp.erl b/test/http_SUITE_data/http_set_resp.erl index 2e7f835..6ac4c8e 100644 --- a/test/http_SUITE_data/http_set_resp.erl +++ b/test/http_SUITE_data/http_set_resp.erl @@ -5,11 +5,11 @@ -export([init/2]). init(Req, Opts) -> - Headers = proplists:get_value(headers, Opts, []), + Headers = proplists:get_value(headers, Opts, #{}), Body = proplists:get_value(body, Opts, <<"http_handler_set_resp">>), Req2 = lists:foldl(fun({Name, Value}, R) -> cowboy_req:set_resp_header(Name, Value, R) - end, Req, Headers), + end, Req, maps:to_list(Headers)), 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), diff --git a/test/http_SUITE_data/http_stream_body.erl b/test/http_SUITE_data/http_stream_body.erl index aea5300..ef10266 100644 --- a/test/http_SUITE_data/http_stream_body.erl +++ b/test/http_SUITE_data/http_stream_body.erl @@ -7,16 +7,22 @@ init(Req, Opts) -> Body = proplists:get_value(body, Opts, "http_handler_stream_body"), Reply = proplists:get_value(reply, Opts), - SFun = fun(Socket, Transport) -> Transport:send(Socket, Body) end, + SFun = fun () -> + cowboy_req:send_body(Body, nofin, Req) + end, Req2 = case Reply of set_resp -> SLen = iolist_size(Body), - cowboy_req:set_resp_body_fun(SLen, SFun, Req); + cowboy_req:set_resp_body({stream, SLen, SFun}, Req); + %% @todo Hmm that one will be sent as chunked now. + %% We need an option to disable chunked. set_resp_close -> - cowboy_req:set_resp_body_fun(SFun, Req); + cowboy_req:set_resp_body({stream, undefined, SFun}, Req); set_resp_chunked -> %% Here Body should be a list of chunks, not a binary. - SFun2 = fun(SendFun) -> lists:foreach(SendFun, Body) end, - cowboy_req:set_resp_body_fun(chunked, SFun2, Req) + SFun2 = fun () -> + lists:foreach(fun (Data) -> cowboy_req:send_body(Data, nofin, Req) end, Body) + end, + cowboy_req:set_resp_body({stream, undefined, SFun2}, Req) end, {ok, cowboy_req:reply(200, Req2), Opts}. diff --git a/test/http_SUITE_data/rest_param_all.erl b/test/http_SUITE_data/rest_param_all.erl index 2b2ea23..d74df74 100644 --- a/test/http_SUITE_data/rest_param_all.erl +++ b/test/http_SUITE_data/rest_param_all.erl @@ -17,7 +17,7 @@ content_types_provided(Req, State) -> {[{{<<"text">>, <<"plain">>, '*'}, get_text_plain}], Req, State}. get_text_plain(Req, State) -> - {_, _, Param} = cowboy_req:meta(media_type, Req, {{<<"text">>, <<"plain">>}, []}), + {_, _, Param} = maps:get(media_type, Req, {{<<"text">>, <<"plain">>}, []}), Body = if Param == '*' -> <<"'*'">>; diff --git a/test/http_SUITE_data/rest_patch_resource.erl b/test/http_SUITE_data/rest_patch_resource.erl index c1244e7..341920d 100644 --- a/test/http_SUITE_data/rest_patch_resource.erl +++ b/test/http_SUITE_data/rest_patch_resource.erl @@ -28,7 +28,7 @@ content_types_accepted(Req, State) -> end. patch_text_plain(Req, State) -> - case cowboy_req:body(Req) of + case cowboy_req:read_body(Req) of {ok, <<"stop">>, Req0} -> {stop, cowboy_req:reply(400, Req0), State}; {ok, <<"false">>, Req0} -> diff --git a/test/rfc7230_SUITE.erl b/test/rfc7230_SUITE.erl index 15d1fc5..480cc4e 100644 --- a/test/rfc7230_SUITE.erl +++ b/test/rfc7230_SUITE.erl @@ -23,12 +23,12 @@ all() -> [{group, http}]. -groups() -> [{http, [parallel], ct_helper:all(?MODULE)}]. +groups() -> [{http, [parallel], ct_helper:all(?MODULE)}]. %% @todo parallel init_per_group(Name = http, Config) -> - cowboy_test:init_http(Name = http, [ - {env, [{dispatch, cowboy_router:compile(init_routes(Config))}]} - ], Config). + cowboy_test:init_http(Name = http, #{ + env => #{dispatch => cowboy_router:compile(init_routes(Config))} + }, Config). end_per_group(Name, _) -> ok = cowboy:stop_listener(Name). @@ -52,9 +52,7 @@ do_raw(Config, Data) -> {Version, Code, Reason, Rest} = cow_http:parse_status_line(raw_recv_head(Client)), {Headers, Rest2} = cow_http:parse_headers(Rest), case lists:keyfind(<<"content-length">>, 1, Headers) of - false -> - #{client => Client, version => Version, code => Code, reason => Reason, headers => Headers, body => <<>>}; - {_, LengthBin} -> + {_, LengthBin} when LengthBin =/= <<"0">> -> Length = binary_to_integer(LengthBin), Body = if byte_size(Rest2) =:= Length -> Rest2; @@ -62,7 +60,9 @@ do_raw(Config, Data) -> {ok, Body0} = raw_recv(Client, binary_to_integer(LengthBin) - byte_size(Rest2), 5000), << Rest2/bits, Body0/bits >> end, - #{client => Client, version => Version, code => Code, reason => Reason, headers => Headers, body => Body} + #{client => Client, version => Version, code => Code, reason => Reason, headers => Headers, body => Body}; + _ -> + #{client => Client, version => Version, code => Code, reason => Reason, headers => Headers, body => <<>>} end. %% Listener. @@ -90,8 +90,8 @@ accept_at_least_1_empty_line(Config) -> reject_response(Config) -> doc("When receiving a response instead of a request, identified by the " "status-line which starts with the HTTP version, the server must " - "reject the message with a 501 status code and close the connection. (RFC7230 3.1)"), - #{code := 501, client := Client} = do_raw(Config, + "reject the message with a 400 status code and close the connection. (RFC7230 3.1)"), + #{code := 400, client := Client} = do_raw(Config, "HTTP/1.1 200 OK\r\n" "\r\n"), {error, closed} = raw_recv(Client, 0, 1000). @@ -138,14 +138,14 @@ timeout_before_request_line(Config) -> "by the reception of a complete request-line."), Client = raw_open(Config), ok = raw_send(Client, "GET / HTTP/1.1\r"), - {error, closed} = raw_recv(Client, 0, 1000). + {error, closed} = raw_recv(Client, 0, 6000). timeout_after_request_line(Config) -> doc("The time the request (request line and headers) takes to be " "received by the server must be limited and subject to configuration. " "A 408 status code must be sent if the request line was received."), #{code := 408, client := Client} = do_raw(Config, "GET / HTTP/1.1\r\n"), - {error, closed} = raw_recv(Client, 0, 1000). + {error, closed} = raw_recv(Client, 0, 6000). %% @todo Add an HTTP/1.0 test suite. %An HTTP/1.1 server must understand any valid HTTP/1.0 request, diff --git a/test/ws_SUITE.erl b/test/ws_SUITE.erl index 4c5bb1d..4eaf456 100644 --- a/test/ws_SUITE.erl +++ b/test/ws_SUITE.erl @@ -37,17 +37,17 @@ init_per_group(Name = autobahn, Config) -> "http://autobahn.ws/testsuite/installation.html"), {skip, "Autobahn Test Suite not installed."}; _ -> - {ok, _} = cowboy:start_http(Name, 100, [{port, 33080}], [ - {env, [{dispatch, init_dispatch()}]}, - {compress, true} - ]), + {ok, _} = cowboy:start_clear(Name, 100, [{port, 33080}], #{ + env => #{dispatch => init_dispatch()}, + compress => true %% @todo Use a separate option for HTTP and Websocket compression. + }), Config end; init_per_group(Name = ws, Config) -> - cowboy_test:init_http(Name, [ - {env, [{dispatch, init_dispatch()}]}, - {compress, true} - ], Config). + cowboy_test:init_http(Name, #{ + env => #{dispatch => init_dispatch()}, + compress => true %% @todo Use a separate option for HTTP and Websocket compression. + }, Config). end_per_group(Listener, _Config) -> cowboy:stop_listener(Listener). diff --git a/test/ws_SUITE_data/ws_echo_timer.erl b/test/ws_SUITE_data/ws_echo_timer.erl index a26c332..9761e1f 100644 --- a/test/ws_SUITE_data/ws_echo_timer.erl +++ b/test/ws_SUITE_data/ws_echo_timer.erl @@ -3,13 +3,17 @@ -module(ws_echo_timer). -export([init/2]). +-export([websocket_init/2]). -export([websocket_handle/3]). -export([websocket_info/3]). init(Req, _) -> - erlang:start_timer(1000, self(), <<"websocket_init">>), {cowboy_websocket, Req, undefined}. +websocket_init(Req, State) -> + erlang:start_timer(1000, self(), <<"websocket_init">>), + {ok, Req, State}. + websocket_handle({text, Data}, Req, State) -> {reply, {text, Data}, Req, State}; websocket_handle({binary, Data}, Req, State) -> diff --git a/test/ws_SUITE_data/ws_send_many.erl b/test/ws_SUITE_data/ws_send_many.erl index 6585ffa..9cee75e 100644 --- a/test/ws_SUITE_data/ws_send_many.erl +++ b/test/ws_SUITE_data/ws_send_many.erl @@ -3,13 +3,17 @@ -module(ws_send_many). -export([init/2]). +-export([websocket_init/2]). -export([websocket_handle/3]). -export([websocket_info/3]). init(Req, Opts) -> - erlang:send_after(10, self(), send_many), {cowboy_websocket, Req, Opts}. +websocket_init(Req, State) -> + erlang:send_after(10, self(), send_many), + {ok, Req, State}. + websocket_handle(_Frame, Req, State) -> {ok, Req, State}. |