diff options
author | Jean-Sébastien Pédron <[email protected]> | 2016-12-29 15:48:06 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2017-01-31 16:19:45 +0100 |
commit | 98c2bc64e5a858db68f260ddd04fed7cee3d80f8 (patch) | |
tree | 7e9c8420fca29fca6027a08d310cbd25aa69e45a /test | |
parent | a62cc4260fd071d522d962ea0a302f6f995152aa (diff) | |
download | cowboy-98c2bc64e5a858db68f260ddd04fed7cee3d80f8.tar.gz cowboy-98c2bc64e5a858db68f260ddd04fed7cee3d80f8.tar.bz2 cowboy-98c2bc64e5a858db68f260ddd04fed7cee3d80f8.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).
(cherry picked from commit 2166733628bbab0eb77eeed58bdf204727c48ec6)
Diffstat (limited to 'test')
-rw-r--r-- | test/http_SUITE.erl | 43 | ||||
-rw-r--r-- | test/http_SUITE_data/static_files_app.ez | bin | 0 -> 1274 bytes |
2 files changed, 43 insertions, 0 deletions
diff --git a/test/http_SUITE.erl b/test/http_SUITE.erl index af3a453..5838f62 100644 --- a/test/http_SUITE.erl +++ b/test/http_SUITE.erl @@ -74,6 +74,11 @@ groups() -> init_per_suite(Config) -> Dir = config(priv_dir, Config) ++ "/static", ct_helper:create_static_dir(Dir), + %% 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), [{static_dir, Dir}|Config]. end_per_suite(Config) -> @@ -189,6 +194,10 @@ init_dispatch(Config) -> [{etag, ?MODULE, do_etag_gen}]}}, {"/static_specify_file/[...]", cowboy_static, {file, config(static_dir, Config) ++ "/style.css"}}, + {"/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"}}, {"/multipart", http_multipart, []}, {"/multipart/large", http_multipart_stream, []}, {"/echo/body", http_echo_body, []}, @@ -966,6 +975,40 @@ static_test_file_css(Config) -> {_, <<"text/css">>} = lists:keyfind(<<"content-type">>, 1, Headers), ok. +priv_file_in_ez_archive(Config) -> + ConnPid = gun_open(Config), + Ref = gun:get(ConnPid, "/ez_priv_file/index.html"), + {response, nofin, 200, Headers} = gun:await(ConnPid, Ref), + {_, <<"text/html">>} = lists:keyfind(<<"content-type">>, 1, Headers), + {ok, <<"<h1>It works!</h1>\n">>} = gun:await_body(ConnPid, Ref), + ok. + +bad_priv_file_in_ez_archive(Config) -> + ConnPid = gun_open(Config), + Ref = gun:get(ConnPid, "/bad/ez_priv_file/index.php"), + {response, fin, 404, _} = gun:await(ConnPid, Ref), + ok. + +priv_dir_in_ez_archive(Config) -> + ConnPid = gun_open(Config), + Ref = gun:get(ConnPid, "/ez_priv_dir/index.html"), + {response, nofin, 200, Headers} = gun:await(ConnPid, Ref), + {_, <<"text/html">>} = lists:keyfind(<<"content-type">>, 1, Headers), + {ok, <<"<h1>It works!</h1>\n">>} = gun:await_body(ConnPid, Ref), + ok. + +bad_file_in_priv_dir_in_ez_archive(Config) -> + ConnPid = gun_open(Config), + Ref = gun:get(ConnPid, "/ez_priv_dir/index.php"), + {response, fin, 404, _} = gun:await(ConnPid, Ref), + ok. + +bad_priv_dir_in_ez_archive(Config) -> + ConnPid = gun_open(Config), + Ref = gun:get(ConnPid, "/bad/ez_priv_dir/index.html"), + {response, fin, 404, _} = gun:await(ConnPid, Ref), + ok. + stream_body_set_resp(Config) -> ConnPid = gun_open(Config), Ref = gun:get(ConnPid, "/stream_body/set_resp"), diff --git a/test/http_SUITE_data/static_files_app.ez b/test/http_SUITE_data/static_files_app.ez Binary files differnew file mode 100644 index 0000000..fdb0911 --- /dev/null +++ b/test/http_SUITE_data/static_files_app.ez |