diff options
author | Loïc Hoguin <[email protected]> | 2018-11-11 16:09:28 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2018-11-11 16:09:28 +0100 |
commit | 7840f6db7b340d4d0630019507eaffa725abbaad (patch) | |
tree | 9ab68d486e6cbf8d516b48e792f956635b3516f1 /test/handlers | |
parent | dd0fbab6b79e1cefa31adf6e9647f0d76bbade06 (diff) | |
download | cowboy-7840f6db7b340d4d0630019507eaffa725abbaad.tar.gz cowboy-7840f6db7b340d4d0630019507eaffa725abbaad.tar.bz2 cowboy-7840f6db7b340d4d0630019507eaffa725abbaad.zip |
Add ProvideRangeCallback tests using sendfile
And fix this case when multiple ranges are requested.
Diffstat (limited to 'test/handlers')
-rw-r--r-- | test/handlers/provide_range_callback_h.erl | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/test/handlers/provide_range_callback_h.erl b/test/handlers/provide_range_callback_h.erl index 136e37e..5b23e07 100644 --- a/test/handlers/provide_range_callback_h.erl +++ b/test/handlers/provide_range_callback_h.erl @@ -43,11 +43,31 @@ get_text_plain(Req, State) -> get_text_plain_bytes(#{qs := <<"missing">>}, _) -> ct_helper_error_h:ignore(cowboy_rest, set_ranged_body_callback, 3), no_call; +get_text_plain_bytes(Req=#{qs := <<"sendfile">>, range := {_, [{From=0, infinity}]}}, State) -> + Path = code:lib_dir(cowboy) ++ "/ebin/cowboy.app", + Size = filelib:file_size(Path), + {[{{From, Size - 1, Size}, {sendfile, From, Size, Path}}], Req, State}; get_text_plain_bytes(Req=#{range := {_, [{From=0, infinity}]}}, State) -> %% We send everything in one part. Body = <<"This is ranged REST!">>, Total = byte_size(Body), {[{{From, Total - 1, Total}, Body}], Req, State}; +get_text_plain_bytes(Req=#{qs := <<"sendfile">>, range := {_, Range}}, State) -> + %% We check the range header we get and send everything hardcoded. + [ + {50, 99}, + {150, 199}, + {250, 299}, + -99 + ] = Range, + Path = code:lib_dir(cowboy) ++ "/ebin/cowboy.app", + Size = filelib:file_size(Path), + {[ + {{50, 99, Size}, {sendfile, 50, 50, Path}}, + {{150, 199, Size}, {sendfile, 150, 50, Path}}, + {{250, 299, Size}, {sendfile, 250, 50, Path}}, + {{Size - 99, Size - 1, Size}, {sendfile, Size - 99, 99, Path}} + ], Req, State}; get_text_plain_bytes(Req=#{range := {_, Range}}, State) -> %% We check the range header we get and send everything hardcoded. [ |