aboutsummaryrefslogtreecommitdiffstats
path: root/test/http_SUITE.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2016-02-10 17:28:32 +0100
committerLoïc Hoguin <[email protected]>2016-03-05 20:20:42 +0100
commitb370442a6352c5acb13b88e135c32ca1720095bd (patch)
tree29485cb24f1b5208b5482358e2c659c9de39bdb3 /test/http_SUITE.erl
parentdbb636034f20736e16eb9d6c809217c9525b6cbd (diff)
downloadcowboy-b370442a6352c5acb13b88e135c32ca1720095bd.tar.gz
cowboy-b370442a6352c5acb13b88e135c32ca1720095bd.tar.bz2
cowboy-b370442a6352c5acb13b88e135c32ca1720095bd.zip
Initial commit with connection/streams
Breaking changes with previous commit. This is a very large change, and I am giving up on making a single commit that fixes everything. More commits will follow slowly adding back features, introducing new tests and fixing the documentation. This change contains most of the work toward unifying the interface for handling both HTTP/1.1 and HTTP/2. HTTP/1.1 connections are now no longer 1 process per connection; instead by default 1 process per request is also created. This has a number of pros and cons. Because it has cons, we also allow users to use a lower-level API that acts on "streams" (requests/responses) directly at the connection process-level. If performance is a concern, one can always write a stream handler. The performance in this case will be even greater than with Cowboy 1, although all the special handlers are unavailable. When switching to Websocket, after the handler returns from init/2, Cowboy stops the stream and the Websocket protocol takes over the connection process. Websocket then calls websocket_init/2 for any additional initialization such as timers, because the process is different in init/2 and websocket_*/* functions. This however would allow us to use websocket_init/2 for sending messages on connect, instead of sending ourselves a message and be subject to races. Note that websocket_init/2 is optional. This is all a big change and while most of the tests pass, some functionality currently doesn't. SPDY is broken and will be removed soon in favor of HTTP/2. Automatic compression is currently disabled. The cowboy_req interface probably still have a few functions that need to be updated. The docs and examples do not refer the current functionality anymore. Everything will be fixed over time. Feedback is more than welcome. Open a ticket!
Diffstat (limited to 'test/http_SUITE.erl')
-rw-r--r--test/http_SUITE.erl70
1 files changed, 34 insertions, 36 deletions
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,