aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_http.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2018-11-03 18:55:40 +0100
committerLoïc Hoguin <[email protected]>2018-11-03 18:55:40 +0100
commitbe09711687218070ee670be7d549df8338b4ae92 (patch)
tree3fd0a125066b2d6eebbe4aee6190e426771c2ee4 /src/cowboy_http.erl
parent571719a164326eebdc792b43170fe27f123aac0d (diff)
downloadcowboy-be09711687218070ee670be7d549df8338b4ae92.tar.gz
cowboy-be09711687218070ee670be7d549df8338b4ae92.tar.bz2
cowboy-be09711687218070ee670be7d549df8338b4ae92.zip
Add an option to disable sendfile for a listener
Diffstat (limited to 'src/cowboy_http.erl')
-rw-r--r--src/cowboy_http.erl9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/cowboy_http.erl b/src/cowboy_http.erl
index 91a539f..9ce7aa8 100644
--- a/src/cowboy_http.erl
+++ b/src/cowboy_http.erl
@@ -44,6 +44,7 @@
middlewares => [module()],
proxy_header => boolean(),
request_timeout => timeout(),
+ sendfile => boolean(),
shutdown_timeout => timeout(),
stream_handlers => [module()],
tracer_callback => cowboy_tracer_h:tracer_callback(),
@@ -1050,7 +1051,7 @@ commands(State=#state{socket=Socket, transport=Transport, streams=Streams, out_s
end,
commands(State#state{out_state=done}, StreamID, Tail);
%% Send a file.
-commands(State0=#state{socket=Socket, transport=Transport}, StreamID,
+commands(State0=#state{socket=Socket, transport=Transport, opts=Opts}, StreamID,
[{sendfile, IsFin, Offset, Bytes, Path}|Tail]) ->
%% @todo exit with response_body_too_large if we exceed content-length
%% We wrap the sendfile call into a try/catch because on OTP-20
@@ -1066,7 +1067,11 @@ commands(State0=#state{socket=Socket, transport=Transport}, StreamID,
%% This try/catch prevents some noisy logs to be written
%% when these errors occur.
try
- Transport:sendfile(Socket, Path, Offset, Bytes),
+ %% When sendfile is disabled we explicitly use the fallback.
+ _ = case maps:get(sendfile, Opts, true) of
+ true -> Transport:sendfile(Socket, Path, Offset, Bytes);
+ false -> ranch_transport:sendfile(Transport, Socket, Path, Offset, Bytes, [])
+ end,
State = case IsFin of
fin -> State0#state{out_state=done}
%% @todo Add the sendfile command.