aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2018-11-11 16:09:28 +0100
committerLoïc Hoguin <[email protected]>2018-11-11 16:09:28 +0100
commit7840f6db7b340d4d0630019507eaffa725abbaad (patch)
tree9ab68d486e6cbf8d516b48e792f956635b3516f1 /src
parentdd0fbab6b79e1cefa31adf6e9647f0d76bbade06 (diff)
downloadcowboy-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 'src')
-rw-r--r--src/cowboy_rest.erl8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/cowboy_rest.erl b/src/cowboy_rest.erl
index d908b40..b874692 100644
--- a/src/cowboy_rest.erl
+++ b/src/cowboy_rest.erl
@@ -1363,7 +1363,13 @@ set_ranged_body_callback(Req, State=#state{handler=Handler}, Callback) ->
%% this for non-bytes units they can always return a single range with a binary
%% content-range information.
{Ranges, Req2, State2} when length(Ranges) > 1 ->
- set_multipart_ranged_body(Req2, State2, Ranges)
+ %% We have to check whether there are sendfile tuples in the
+ %% ranges to be sent. If there are we must use stream_reply.
+ HasSendfile = [] =/= [true || {_, {sendfile, _, _, _}} <- Ranges],
+ case HasSendfile of
+ true -> send_multipart_ranged_body(Req2, State2, Ranges);
+ false -> set_multipart_ranged_body(Req2, State2, Ranges)
+ end
end catch Class:{case_clause, no_call} ->
error_terminate(Req, State, Class, {error, {missing_callback, {Handler, Callback, 2}},
'A callback specified in ranges_provided/2 is not exported.'})