From 7840f6db7b340d4d0630019507eaffa725abbaad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Sun, 11 Nov 2018 16:09:28 +0100 Subject: Add ProvideRangeCallback tests using sendfile And fix this case when multiple ranges are requested. --- src/cowboy_rest.erl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') 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.'}) -- cgit v1.2.3