aboutsummaryrefslogtreecommitdiffstats
path: root/test/static_handler_SUITE.erl
diff options
context:
space:
mode:
authorJean-Sébastien Pédron <[email protected]>2016-12-29 15:48:06 +0100
committerLoïc Hoguin <[email protected]>2017-01-24 11:36:58 +0100
commit2166733628bbab0eb77eeed58bdf204727c48ec6 (patch)
treecb94448fd394a162af90daf6885c9e3aaa64d53a /test/static_handler_SUITE.erl
parent3c198f7d90ee7b482ee00e66d12699dd645442e7 (diff)
downloadcowboy-2166733628bbab0eb77eeed58bdf204727c48ec6.tar.gz
cowboy-2166733628bbab0eb77eeed58bdf204727c48ec6.tar.bz2
cowboy-2166733628bbab0eb77eeed58bdf204727c48ec6.zip
cowboy_static: Add support for files in EZ archives
If cowboy_static is initialized with `{priv_file, ...}` or `{priv_dir, ...}`, it is now able to read files from Erlang application .ez archives. When serving a file from an archive, the #file_info{} comes from the archive, not the contained file, except for the size and type. The erl_prim_loader module is used to read the latter's #file_info{} and the actual file content (ie. sendfile(2) is not used in this case).
Diffstat (limited to 'test/static_handler_SUITE.erl')
-rw-r--r--test/static_handler_SUITE.erl38
1 files changed, 37 insertions, 1 deletions
diff --git a/test/static_handler_SUITE.erl b/test/static_handler_SUITE.erl
index 78926ee..7a6517f 100644
--- a/test/static_handler_SUITE.erl
+++ b/test/static_handler_SUITE.erl
@@ -59,6 +59,11 @@ init_per_suite(Config) ->
ct_helper:create_static_dir(StaticDir),
init_large_file(PrivDir ++ "/large.bin"),
init_large_file(StaticDir ++ "/large.bin"),
+ %% Add a simple Erlang application archive containing one file
+ %% in its priv directory.
+ true = code:add_pathz(filename:join(
+ [config(data_dir, Config), "static_files_app", "ebin"])),
+ ok = application:load(static_files_app),
%% A special folder contains files of 1 character from 0 to 127.
CharDir = config(priv_dir, Config) ++ "/char",
ok = filelib:ensure_dir(CharDir ++ "/file"),
@@ -146,7 +151,11 @@ init_dispatch(Config) ->
{"/bad/options/mime", cowboy_static, {priv_file, ct_helper, "static/style.css", [{mimetypes, bad}]}},
{"/bad/options/etag", cowboy_static, {priv_file, ct_helper, "static/style.css", [{etag, true}]}},
{"/unknown/option", cowboy_static, {priv_file, ct_helper, "static/style.css", [{bad, option}]}},
- {"/char/[...]", cowboy_static, {dir, config(char_dir, Config)}}
+ {"/char/[...]", cowboy_static, {dir, config(char_dir, Config)}},
+ {"/ez_priv_file/index.html", cowboy_static, {priv_file, static_files_app, "www/index.html"}},
+ {"/bad/ez_priv_file/index.php", cowboy_static, {priv_file, static_files_app, "www/index.php"}},
+ {"/ez_priv_dir/[...]", cowboy_static, {priv_dir, static_files_app, "www"}},
+ {"/bad/ez_priv_dir/[...]", cowboy_static, {priv_dir, static_files_app, "cgi-bin"}}
]}]).
%% Internal functions.
@@ -762,3 +771,30 @@ unknown_option(Config) ->
{200, Headers, <<"body{color:red}\n">>} = do_get("/unknown/option", Config),
{_, <<"text/css">>} = lists:keyfind(<<"content-type">>, 1, Headers),
ok.
+
+priv_file_in_ez_archive(Config) ->
+ doc("Get a file stored in Erlang application .ez archive."),
+ {200, Headers, <<"<h1>It works!</h1>\n">>} = do_get("/ez_priv_file/index.html", Config),
+ {_, <<"text/html">>} = lists:keyfind(<<"content-type">>, 1, Headers),
+ ok.
+
+bad_priv_file_in_ez_archive(Config) ->
+ doc("Bad cowboy_static options: priv_file path missing from Erlang application .ez archive."),
+ {404, _, _} = do_get("/bad/ez_priv_file/index.php", Config),
+ ok.
+
+priv_dir_in_ez_archive(Config) ->
+ doc("Get a file from a priv_dir stored in Erlang application .ez archive."),
+ {200, Headers, <<"<h1>It works!</h1>\n">>} = do_get("/ez_priv_dir/index.html", Config),
+ {_, <<"text/html">>} = lists:keyfind(<<"content-type">>, 1, Headers),
+ ok.
+
+bad_file_in_priv_dir_in_ez_archive(Config) ->
+ doc("Get a missing file from a priv_dir stored in Erlang application .ez archive."),
+ {404, _, _} = do_get("/ez_priv_dir/index.php", Config),
+ ok.
+
+bad_priv_dir_in_ez_archive(Config) ->
+ doc("Bad cowboy_static options: priv_dir path missing from Erlang application .ez archive."),
+ {404, _, _} = do_get("/bad/ez_priv_dir/index.html", Config),
+ ok.