aboutsummaryrefslogtreecommitdiffstats
path: root/test/http_SUITE.erl
diff options
context:
space:
mode:
Diffstat (limited to 'test/http_SUITE.erl')
-rw-r--r--test/http_SUITE.erl55
1 files changed, 32 insertions, 23 deletions
diff --git a/test/http_SUITE.erl b/test/http_SUITE.erl
index b536380..f0196ec 100644
--- a/test/http_SUITE.erl
+++ b/test/http_SUITE.erl
@@ -25,6 +25,10 @@
-export([init_per_group/2]).
-export([end_per_group/2]).
+%% Callbacks.
+-export([etag_gen/3]).
+-export([mimetypes_text_html/1]).
+
%% Tests.
-export([check_raw_status/1]).
-export([check_status/1]).
@@ -86,6 +90,7 @@
-export([stream_body_set_resp_close/1]).
-export([stream_body_set_resp_chunked/1]).
-export([stream_body_set_resp_chunked10/1]).
+-export([streamed_response/1]).
-export([te_chunked/1]).
-export([te_chunked_chopped/1]).
-export([te_chunked_delayed/1]).
@@ -163,6 +168,7 @@ groups() ->
stream_body_set_resp_close,
stream_body_set_resp_chunked,
stream_body_set_resp_chunked10,
+ streamed_response,
te_chunked,
te_chunked_chopped,
te_chunked_delayed,
@@ -348,6 +354,7 @@ init_dispatch(Config) ->
cowboy_router:compile([
{"localhost", [
{"/chunked_response", http_chunked, []},
+ {"/streamed_response", http_streamed, []},
{"/init_shutdown", http_init_shutdown, []},
{"/long_polling", http_long_polling, []},
{"/headers/dupe", http_handler,
@@ -369,23 +376,18 @@ init_dispatch(Config) ->
{reply, set_resp_chunked},
{body, [<<"stream_body">>, <<"_set_resp_chunked">>]}]},
{"/static/[...]", cowboy_static,
- [{directory, ?config(static_dir, Config)},
- {mimetypes, [{<<".css">>, [<<"text/css">>]}]}]},
+ {dir, ?config(static_dir, Config)}},
{"/static_mimetypes_function/[...]", cowboy_static,
- [{directory, ?config(static_dir, Config)},
- {mimetypes, {fun(Path, data) when is_binary(Path) ->
- [<<"text/html">>] end, data}}]},
+ {dir, ?config(static_dir, Config),
+ [{mimetypes, ?MODULE, mimetypes_text_html}]}},
{"/handler_errors", http_errors, []},
{"/static_attribute_etag/[...]", cowboy_static,
- [{directory, ?config(static_dir, Config)},
- {etag, {attributes, [filepath, filesize, inode, mtime]}}]},
+ {dir, ?config(static_dir, Config)}},
{"/static_function_etag/[...]", cowboy_static,
- [{directory, ?config(static_dir, Config)},
- {etag, {fun static_function_etag/2, etag_data}}]},
- {"/static_specify_file/[...]", cowboy_static,
- [{directory, ?config(static_dir, Config)},
- {mimetypes, [{<<".css">>, [<<"text/css">>]}]},
- {file, <<"style.css">>}]},
+ {dir, ?config(static_dir, Config),
+ [{etag, ?MODULE, etag_gen}]}},
+ {"/static_specify_file/[...]", cowboy_static,
+ {file, ?config(static_dir, Config) ++ "/style.css"}},
{"/multipart", http_multipart, []},
{"/echo/body", http_echo_body, []},
{"/echo/body_qs", http_body_qs, []},
@@ -410,6 +412,12 @@ init_dispatch(Config) ->
]}
]).
+etag_gen(_, _, _) ->
+ {strong, <<"etag">>}.
+
+mimetypes_text_html(_) ->
+ <<"text/html">>.
+
%% Convenience functions.
quick_raw(Data, Config) ->
@@ -1175,16 +1183,6 @@ static_function_etag(Config) ->
false = ETag1 =:= undefined,
ETag1 = ETag2.
-%% Callback function for generating the ETag for the above test.
-static_function_etag(Arguments, etag_data) ->
- {_, Filepath} = lists:keyfind(filepath, 1, Arguments),
- {_, _Filesize} = lists:keyfind(filesize, 1, Arguments),
- {_, _INode} = lists:keyfind(inode, 1, Arguments),
- {_, _Modified} = lists:keyfind(mtime, 1, Arguments),
- ChecksumCommand = lists:flatten(io_lib:format("sha1sum ~s", [Filepath])),
- [Checksum|_] = string:tokens(os:cmd(ChecksumCommand), " "),
- {strong, iolist_to_binary(Checksum)}.
-
static_mimetypes_function(Config) ->
Client = ?config(client, Config),
{ok, Client2} = cowboy_client:request(<<"GET">>,
@@ -1290,6 +1288,17 @@ stream_body_set_resp_chunked10(Config) ->
end,
{error, closed} = Transport:recv(Socket, 0, 1000).
+streamed_response(Config) ->
+ Client = ?config(client, Config),
+ {ok, Client2} = cowboy_client:request(<<"GET">>,
+ build_url("/streamed_response", Config), Client),
+ {ok, 200, Headers, Client3} = cowboy_client:response(Client2),
+ false = lists:keymember(<<"transfer-encoding">>, 1, Headers),
+ {ok, Transport, Socket} = cowboy_client:transport(Client3),
+ {ok, <<"streamed_handler\r\nworks fine!">>}
+ = Transport:recv(Socket, 29, 1000),
+ {error, closed} = cowboy_client:response(Client3).
+
te_chunked(Config) ->
Client = ?config(client, Config),
Body = list_to_binary(io_lib:format("~p", [lists:seq(1, 100)])),