diff options
Diffstat (limited to 'test/handlers')
-rw-r--r-- | test/handlers/provide_range_callback_h.erl | 4 | ||||
-rw-r--r-- | test/handlers/ranges_provided_auto_h.erl | 27 |
2 files changed, 29 insertions, 2 deletions
diff --git a/test/handlers/provide_range_callback_h.erl b/test/handlers/provide_range_callback_h.erl index f14a544..136e37e 100644 --- a/test/handlers/provide_range_callback_h.erl +++ b/test/handlers/provide_range_callback_h.erl @@ -1,4 +1,4 @@ -%% This module defines the range_satisfiable callback +%% This module defines many callbacks relevant to range requests %% and return something different depending on query string. -module(provide_range_callback_h). @@ -41,7 +41,7 @@ get_text_plain(Req, State) -> %% Simulate the callback being missing, otherwise expect true/false. get_text_plain_bytes(#{qs := <<"missing">>}, _) -> - ct_helper_error_h:ignore(cowboy_rest, set_ranged_body, 3), + ct_helper_error_h:ignore(cowboy_rest, set_ranged_body_callback, 3), no_call; get_text_plain_bytes(Req=#{range := {_, [{From=0, infinity}]}}, State) -> %% We send everything in one part. diff --git a/test/handlers/ranges_provided_auto_h.erl b/test/handlers/ranges_provided_auto_h.erl new file mode 100644 index 0000000..f7e6595 --- /dev/null +++ b/test/handlers/ranges_provided_auto_h.erl @@ -0,0 +1,27 @@ +%% This module defines the ranges_provided callback +%% which returns the auto option for bytes ranges +%% and the normal ProvideCallback that returns +%% something different depending on query string. + +-module(ranges_provided_auto_h). + +-export([init/2]). +-export([content_types_provided/2]). +-export([ranges_provided/2]). +-export([get_text_plain/2]). + +init(Req, State) -> + {cowboy_rest, Req, State}. + +content_types_provided(Req, State) -> + {[{{<<"text">>, <<"plain">>, []}, get_text_plain}], Req, State}. + +ranges_provided(Req, State) -> + {[{<<"bytes">>, auto}], Req, State}. + +get_text_plain(Req=#{qs := <<"data">>}, State) -> + {<<"This is ranged REST!">>, Req, State}; +get_text_plain(Req=#{qs := <<"sendfile">>}, State) -> + Path = code:lib_dir(cowboy) ++ "/ebin/cowboy.app", + Size = filelib:file_size(Path), + {{sendfile, 0, Size, Path}, Req, State}. |