aboutsummaryrefslogtreecommitdiffstats
path: root/test/http_SUITE_data
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2018-03-26 18:49:09 +0200
committerLoïc Hoguin <[email protected]>2018-03-26 18:53:07 +0200
commit5964273cc4354b7378b8bdf49fe455d2b46d7c3b (patch)
tree38194d0ae9a16056fff8e1c062fe6c6267d2d24c /test/http_SUITE_data
parent4d5174632cc1feac541697b18e6fbbdd0eed021b (diff)
downloadcowboy-5964273cc4354b7378b8bdf49fe455d2b46d7c3b.tar.gz
cowboy-5964273cc4354b7378b8bdf49fe455d2b46d7c3b.tar.bz2
cowboy-5964273cc4354b7378b8bdf49fe455d2b46d7c3b.zip
Fix the flushing of messages when switching to Websocket
We now flush messages that are specific to cowboy_http only. Stream handlers should also flush their own specific messages if necessary, although timeouts will be flushed regardless of where they originate from. Also renames the http_SUITE to old_http_SUITE to distinguish new tests from old tests. Most old tests need to be removed or converted eventually as they're legacy tests from Cowboy 1.0.
Diffstat (limited to 'test/http_SUITE_data')
-rw-r--r--test/http_SUITE_data/http_chunked.erl15
-rw-r--r--test/http_SUITE_data/http_echo_body.erl21
-rw-r--r--test/http_SUITE_data/http_errors.erl17
-rw-r--r--test/http_SUITE_data/http_handler.erl10
-rw-r--r--test/http_SUITE_data/http_loop_stream_recv.erl34
-rw-r--r--test/http_SUITE_data/http_req_attr.erl15
-rw-r--r--test/http_SUITE_data/http_set_resp.erl25
-rw-r--r--test/http_SUITE_data/rest_empty_resource.erl6
-rw-r--r--test/http_SUITE_data/rest_expires.erl22
-rw-r--r--test/http_SUITE_data/rest_expires_binary.erl18
-rw-r--r--test/http_SUITE_data/rest_forbidden_resource.erl32
-rw-r--r--test/http_SUITE_data/rest_missing_callbacks.erl24
-rw-r--r--test/http_SUITE_data/rest_nodelete_resource.erl18
-rw-r--r--test/http_SUITE_data/rest_param_all.erl36
-rw-r--r--test/http_SUITE_data/rest_patch_resource.erl38
-rw-r--r--test/http_SUITE_data/rest_post_charset_resource.erl19
-rw-r--r--test/http_SUITE_data/rest_postonly_resource.erl18
-rw-r--r--test/http_SUITE_data/rest_resource_etags.erl37
-rw-r--r--test/http_SUITE_data/rest_simple_resource.erl14
19 files changed, 0 insertions, 419 deletions
diff --git a/test/http_SUITE_data/http_chunked.erl b/test/http_SUITE_data/http_chunked.erl
deleted file mode 100644
index 645eefe..0000000
--- a/test/http_SUITE_data/http_chunked.erl
+++ /dev/null
@@ -1,15 +0,0 @@
-%% Feel free to use, reuse and abuse the code in this file.
-
--module(http_chunked).
-
--export([init/2]).
-
-init(Req, Opts) ->
- Req2 = cowboy_req:stream_reply(200, Req),
- %% Try an empty chunk to make sure the stream doesn't get closed.
- cowboy_req:stream_body([<<>>], nofin, Req2),
- timer:sleep(100),
- cowboy_req:stream_body("chunked_handler\r\n", nofin, Req2),
- timer:sleep(100),
- cowboy_req:stream_body("works fine!", fin, Req2),
- {ok, Req2, Opts}.
diff --git a/test/http_SUITE_data/http_echo_body.erl b/test/http_SUITE_data/http_echo_body.erl
deleted file mode 100644
index d803108..0000000
--- a/test/http_SUITE_data/http_echo_body.erl
+++ /dev/null
@@ -1,21 +0,0 @@
-%% Feel free to use, reuse and abuse the code in this file.
-
--module(http_echo_body).
-
--export([init/2]).
-
-init(Req, Opts) ->
- true = cowboy_req:has_body(Req),
- 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).
-
-handle_body(Req, Body) ->
- Size = cowboy_req:body_length(Req),
- Size = byte_size(Body),
- cowboy_req:reply(200, #{}, Body, Req).
diff --git a/test/http_SUITE_data/http_errors.erl b/test/http_SUITE_data/http_errors.erl
deleted file mode 100644
index 14e3d09..0000000
--- a/test/http_SUITE_data/http_errors.erl
+++ /dev/null
@@ -1,17 +0,0 @@
-%% Feel free to use, reuse and abuse the code in this file.
-
--module(http_errors).
-
--export([init/2]).
-
-init(Req, _Opts) ->
- #{'case' := Case} = cowboy_req:match_qs(['case'], Req),
- case_init(Case, Req).
-
-case_init(<<"init_before_reply">> = Case, _Req) ->
- ct_helper_error_h:ignore(?MODULE, case_init, 2),
- 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),
- error(Case).
diff --git a/test/http_SUITE_data/http_handler.erl b/test/http_SUITE_data/http_handler.erl
deleted file mode 100644
index eb31aa8..0000000
--- a/test/http_SUITE_data/http_handler.erl
+++ /dev/null
@@ -1,10 +0,0 @@
-%% Feel free to use, reuse and abuse the code in this file.
-
--module(http_handler).
-
--export([init/2]).
-
-init(Req, 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_loop_stream_recv.erl b/test/http_SUITE_data/http_loop_stream_recv.erl
deleted file mode 100644
index 8c6f6b0..0000000
--- a/test/http_SUITE_data/http_loop_stream_recv.erl
+++ /dev/null
@@ -1,34 +0,0 @@
-%% Feel free to use, reuse and abuse the code in this file.
-
--module(http_loop_stream_recv).
-
--export([init/2]).
--export([info/3]).
--export([terminate/3]).
-
-init(Req, _) ->
- receive after 100 -> ok end,
- self() ! stream,
- {cowboy_loop, Req, undefined}.
-
-info(stream, Req, undefined) ->
- stream(Req, 1, <<>>).
-
-stream(Req, ID, Acc) ->
- case cowboy_req:read_body(Req) of
- {ok, <<>>, Req2} ->
- {stop, cowboy_req:reply(200, Req2), undefined};
- {_, Data, Req2} ->
- parse_id(Req2, ID, << Acc/binary, Data/binary >>)
- end.
-
-parse_id(Req, ID, Data) ->
- case Data of
- << ID:32, Rest/bits >> ->
- parse_id(Req, ID + 1, Rest);
- _ ->
- stream(Req, ID, Data)
- end.
-
-terminate(stop, _, _) ->
- ok.
diff --git a/test/http_SUITE_data/http_req_attr.erl b/test/http_SUITE_data/http_req_attr.erl
deleted file mode 100644
index c6a940e..0000000
--- a/test/http_SUITE_data/http_req_attr.erl
+++ /dev/null
@@ -1,15 +0,0 @@
-%% 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).
-
--export([init/2]).
-
-init(Req, Opts) ->
- #{attr := Attr} = cowboy_req:match_qs([attr], Req),
- <<"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), Opts}.
diff --git a/test/http_SUITE_data/http_set_resp.erl b/test/http_SUITE_data/http_set_resp.erl
deleted file mode 100644
index e575aab..0000000
--- a/test/http_SUITE_data/http_set_resp.erl
+++ /dev/null
@@ -1,25 +0,0 @@
-%% Feel free to use, reuse and abuse the code in this file.
-
--module(http_set_resp).
-
--export([init/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) ->
- cowboy_req:set_resp_header(Name, Value, R)
- 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),
- case cowboy_req:has_resp_header(<<"x-cowboy-test">>, Req5) of
- false -> {ok, Req5, Opts};
- true ->
- case cowboy_req:has_resp_body(Req5) of
- false ->
- {ok, Req5, Opts};
- true ->
- {ok, cowboy_req:reply(200, Req5), Opts}
- end
- end.
diff --git a/test/http_SUITE_data/rest_empty_resource.erl b/test/http_SUITE_data/rest_empty_resource.erl
deleted file mode 100644
index 8a944cd..0000000
--- a/test/http_SUITE_data/rest_empty_resource.erl
+++ /dev/null
@@ -1,6 +0,0 @@
--module(rest_empty_resource).
-
--export([init/2]).
-
-init(Req, Opts) ->
- {cowboy_rest, Req, Opts}.
diff --git a/test/http_SUITE_data/rest_expires.erl b/test/http_SUITE_data/rest_expires.erl
deleted file mode 100644
index 8665b06..0000000
--- a/test/http_SUITE_data/rest_expires.erl
+++ /dev/null
@@ -1,22 +0,0 @@
--module(rest_expires).
-
--export([init/2]).
--export([content_types_provided/2]).
--export([get_text_plain/2]).
--export([expires/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}.
-
-expires(Req, State) ->
- {{{2012, 9, 21}, {22, 36, 14}}, Req, State}.
-
-last_modified(Req, State) ->
- {{{2012, 9, 21}, {22, 36, 14}}, Req, State}.
diff --git a/test/http_SUITE_data/rest_expires_binary.erl b/test/http_SUITE_data/rest_expires_binary.erl
deleted file mode 100644
index 4d6bd3c..0000000
--- a/test/http_SUITE_data/rest_expires_binary.erl
+++ /dev/null
@@ -1,18 +0,0 @@
--module(rest_expires_binary).
-
--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, State) ->
- {<<"0">>, Req, State}.
diff --git a/test/http_SUITE_data/rest_forbidden_resource.erl b/test/http_SUITE_data/rest_forbidden_resource.erl
deleted file mode 100644
index 0a65228..0000000
--- a/test/http_SUITE_data/rest_forbidden_resource.erl
+++ /dev/null
@@ -1,32 +0,0 @@
--module(rest_forbidden_resource).
-
--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]).
-
-init(Req, [Forbidden]) ->
- {cowboy_rest, Req, Forbidden}.
-
-allowed_methods(Req, State) ->
- {[<<"GET">>, <<"HEAD">>, <<"POST">>], Req, State}.
-
-forbidden(Req, State=true) ->
- {true, Req, State};
-forbidden(Req, State=false) ->
- {false, Req, State}.
-
-content_types_provided(Req, State) ->
- {[{{<<"text">>, <<"plain">>, []}, to_text}], Req, State}.
-
-content_types_accepted(Req, State) ->
- {[{{<<"text">>, <<"plain">>, []}, from_text}], Req, State}.
-
-to_text(Req, State) ->
- {<<"This is REST!">>, Req, State}.
-
-from_text(Req, State) ->
- {{true, cowboy_req:path(Req)}, Req, State}.
diff --git a/test/http_SUITE_data/rest_missing_callbacks.erl b/test/http_SUITE_data/rest_missing_callbacks.erl
deleted file mode 100644
index bf77c22..0000000
--- a/test/http_SUITE_data/rest_missing_callbacks.erl
+++ /dev/null
@@ -1,24 +0,0 @@
--module(rest_missing_callbacks).
-
--export([init/2]).
--export([allowed_methods/2]).
--export([content_types_accepted/2]).
--export([content_types_provided/2]).
-
-init(Req, Opts) ->
- {cowboy_rest, Req, Opts}.
-
-allowed_methods(Req, State) ->
- {[<<"GET">>, <<"PUT">>], Req, State}.
-
-content_types_accepted(Req, State) ->
- ct_helper_error_h:ignore(cowboy_rest, process_content_type, 3),
- {[
- {<<"application/json">>, put_application_json}
- ], Req, State}.
-
-content_types_provided(Req, State) ->
- ct_helper_error_h:ignore(cowboy_rest, set_resp_body, 2),
- {[
- {<<"text/plain">>, get_text_plain}
- ], Req, State}.
diff --git a/test/http_SUITE_data/rest_nodelete_resource.erl b/test/http_SUITE_data/rest_nodelete_resource.erl
deleted file mode 100644
index b9f40bd..0000000
--- a/test/http_SUITE_data/rest_nodelete_resource.erl
+++ /dev/null
@@ -1,18 +0,0 @@
--module(rest_nodelete_resource).
-
--export([init/2]).
--export([allowed_methods/2]).
--export([content_types_provided/2]).
--export([get_text_plain/2]).
-
-init(Req, Opts) ->
- {cowboy_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
deleted file mode 100644
index 784214b..0000000
--- a/test/http_SUITE_data/rest_param_all.erl
+++ /dev/null
@@ -1,36 +0,0 @@
--module(rest_param_all).
-
--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(Req, Opts) ->
- {cowboy_rest, Req, Opts}.
-
-allowed_methods(Req, State) ->
- {[<<"GET">>, <<"PUT">>], Req, State}.
-
-content_types_provided(Req, State) ->
- {[{{<<"text">>, <<"plain">>, '*'}, get_text_plain}], Req, State}.
-
-get_text_plain(Req, State) ->
- {_, _, Param} = maps:get(media_type, Req, {<<"text">>, <<"plain">>, []}),
- Body = if
- Param == '*' ->
- <<"'*'">>;
- Param == [] ->
- <<"[]">>;
- Param /= [] ->
- iolist_to_binary([[Key, $=, Value] || {Key, Value} <- Param])
- end,
- {Body, Req, State}.
-
-content_types_accepted(Req, State) ->
- {[{{<<"text">>, <<"plain">>, '*'}, put_text_plain}], Req, State}.
-
-put_text_plain(Req0, State) ->
- {ok, _, Req} = cowboy_req:read_body(Req0),
- {true, Req, State}.
diff --git a/test/http_SUITE_data/rest_patch_resource.erl b/test/http_SUITE_data/rest_patch_resource.erl
deleted file mode 100644
index 341920d..0000000
--- a/test/http_SUITE_data/rest_patch_resource.erl
+++ /dev/null
@@ -1,38 +0,0 @@
--module(rest_patch_resource).
-
--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) ->
- {cowboy_rest, Req, Opts}.
-
-allowed_methods(Req, State) ->
- {[<<"HEAD">>, <<"GET">>, <<"PATCH">>], Req, State}.
-
-content_types_provided(Req, State) ->
- {[{{<<"text">>, <<"plain">>, []}, get_text_plain}], Req, State}.
-
-get_text_plain(Req, State) ->
- {<<"This is REST!">>, Req, State}.
-
-content_types_accepted(Req, State) ->
- case cowboy_req:method(Req) of
- <<"PATCH">> ->
- {[{{<<"text">>, <<"plain">>, []}, patch_text_plain}], Req, State};
- _ ->
- {[], Req, State}
- end.
-
-patch_text_plain(Req, State) ->
- case cowboy_req:read_body(Req) of
- {ok, <<"stop">>, Req0} ->
- {stop, cowboy_req:reply(400, Req0), State};
- {ok, <<"false">>, Req0} ->
- {false, Req0, State};
- {ok, _Body, Req0} ->
- {true, Req0, State}
- end.
diff --git a/test/http_SUITE_data/rest_post_charset_resource.erl b/test/http_SUITE_data/rest_post_charset_resource.erl
deleted file mode 100644
index 0be6aa3..0000000
--- a/test/http_SUITE_data/rest_post_charset_resource.erl
+++ /dev/null
@@ -1,19 +0,0 @@
--module(rest_post_charset_resource).
-
--export([init/2]).
--export([allowed_methods/2]).
--export([content_types_accepted/2]).
--export([from_text/2]).
-
-init(Req, Opts) ->
- {cowboy_rest, Req, Opts}.
-
-allowed_methods(Req, State) ->
- {[<<"POST">>], Req, State}.
-
-content_types_accepted(Req, State) ->
- {[{{<<"text">>, <<"plain">>, [{<<"charset">>, <<"utf-8">>}]},
- from_text}], Req, State}.
-
-from_text(Req, State) ->
- {true, Req, State}.
diff --git a/test/http_SUITE_data/rest_postonly_resource.erl b/test/http_SUITE_data/rest_postonly_resource.erl
deleted file mode 100644
index 942e55d..0000000
--- a/test/http_SUITE_data/rest_postonly_resource.erl
+++ /dev/null
@@ -1,18 +0,0 @@
--module(rest_postonly_resource).
-
--export([init/2]).
--export([allowed_methods/2]).
--export([content_types_accepted/2]).
--export([from_text/2]).
-
-init(Req, Opts) ->
- {cowboy_rest, Req, Opts}.
-
-allowed_methods(Req, State) ->
- {[<<"POST">>], Req, State}.
-
-content_types_accepted(Req, State) ->
- {[{{<<"text">>, <<"plain">>, '*'}, from_text}], Req, State}.
-
-from_text(Req, State) ->
- {true, Req, State}.
diff --git a/test/http_SUITE_data/rest_resource_etags.erl b/test/http_SUITE_data/rest_resource_etags.erl
deleted file mode 100644
index 25b3080..0000000
--- a/test/http_SUITE_data/rest_resource_etags.erl
+++ /dev/null
@@ -1,37 +0,0 @@
--module(rest_resource_etags).
-
--export([init/2]).
--export([generate_etag/2]).
--export([content_types_provided/2]).
--export([get_text_plain/2]).
-
-init(Req, Opts) ->
- {cowboy_rest, Req, Opts}.
-
-generate_etag(Req, State) ->
- #{type := Type} = cowboy_req:match_qs([type], Req),
- case Type of
- %% Correct return values from generate_etag/2.
- <<"tuple-weak">> ->
- {{weak, <<"etag-header-value">>}, Req, State};
- <<"tuple-strong">> ->
- {{strong, <<"etag-header-value">>}, Req, State};
- %% Backwards compatible return values from generate_etag/2.
- <<"binary-weak-quoted">> ->
- {<<"W/\"etag-header-value\"">>, Req, State};
- <<"binary-strong-quoted">> ->
- {<<"\"etag-header-value\"">>, Req, State};
- %% Invalid return values from generate_etag/2.
- <<"binary-strong-unquoted">> ->
- ct_helper_error_h:ignore(cow_http_hd, parse_etag, 1),
- {<<"etag-header-value">>, Req, State};
- <<"binary-weak-unquoted">> ->
- ct_helper_error_h:ignore(cow_http_hd, parse_etag, 1),
- {<<"W/etag-header-value">>, Req, State}
- end.
-
-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_simple_resource.erl b/test/http_SUITE_data/rest_simple_resource.erl
deleted file mode 100644
index 68e1b95..0000000
--- a/test/http_SUITE_data/rest_simple_resource.erl
+++ /dev/null
@@ -1,14 +0,0 @@
--module(rest_simple_resource).
-
--export([init/2]).
--export([content_types_provided/2]).
--export([get_text_plain/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}.