aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/cowboy_static.erl9
-rw-r--r--test/static_handler_SUITE.erl9
2 files changed, 18 insertions, 0 deletions
diff --git a/src/cowboy_static.erl b/src/cowboy_static.erl
index 335c6ae..29ac809 100644
--- a/src/cowboy_static.erl
+++ b/src/cowboy_static.erl
@@ -20,6 +20,7 @@
-export([forbidden/2]).
-export([content_types_provided/2]).
-export([charsets_provided/2]).
+-export([ranges_provided/2]).
-export([resource_exists/2]).
-export([last_modified/2]).
-export([generate_etag/2]).
@@ -340,6 +341,14 @@ charsets_provided(Req, State={Path, _, Extra}) ->
{[Charset], Req, State}
end.
+%% Enable support for range requests.
+
+-spec ranges_provided(Req, State)
+ -> {[{binary(), auto}], Req, State}
+ when State::state().
+ranges_provided(Req, State) ->
+ {[{<<"bytes">>, auto}], Req, State}.
+
%% Assume the resource doesn't exist if it's not a regular file.
-spec resource_exists(Req, State)
diff --git a/test/static_handler_SUITE.erl b/test/static_handler_SUITE.erl
index 6467f5b..786438a 100644
--- a/test/static_handler_SUITE.erl
+++ b/test/static_handler_SUITE.erl
@@ -838,6 +838,15 @@ priv_file_in_ez_archive(Config) ->
{_, <<"text/html">>} = lists:keyfind(<<"content-type">>, 1, Headers),
ok.
+range_request(Config) ->
+ doc("Confirm that range requests are enabled."),
+ {206, Headers, <<"less space.\n">>} = do_get("/dir/plain.txt",
+ [{<<"range">>, <<"bytes=4-">>}], Config),
+ {_, <<"bytes">>} = lists:keyfind(<<"accept-ranges">>, 1, Headers),
+ {_, <<"bytes 4-15/16">>} = lists:keyfind(<<"content-range">>, 1, Headers),
+ {_, <<"application/octet-stream">>} = lists:keyfind(<<"content-type">>, 1, Headers),
+ ok.
+
unicode_basic_latin(Config) ->
doc("Get a file with non-urlencoded characters from Unicode Basic Latin block."),
_ = [case do_get("/char/" ++ [C], Config) of