0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 12:20:24 +00:00

Add an option to disable sendfile for a listener

This commit is contained in:
Loïc Hoguin 2018-11-03 18:55:40 +01:00
parent 571719a164
commit be09711687
No known key found for this signature in database
GPG key ID: 8A9DF795F6FED764
5 changed files with 48 additions and 8 deletions

View file

@ -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.