aboutsummaryrefslogtreecommitdiffstats
path: root/test/http_SUITE_data
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_data
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_data')
-rw-r--r--test/http_SUITE_data/http_body_qs.erl12
-rw-r--r--test/http_SUITE_data/http_echo_body.erl6
-rw-r--r--test/http_SUITE_data/http_errors.erl2
-rw-r--r--test/http_SUITE_data/http_handler.erl2
-rw-r--r--test/http_SUITE_data/http_multipart.erl2
-rw-r--r--test/http_SUITE_data/http_req_attr.erl2
-rw-r--r--test/http_SUITE_data/http_set_resp.erl4
-rw-r--r--test/http_SUITE_data/http_stream_body.erl16
-rw-r--r--test/http_SUITE_data/rest_param_all.erl2
-rw-r--r--test/http_SUITE_data/rest_patch_resource.erl2
10 files changed, 28 insertions, 22 deletions
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} ->