diff options
author | Loïc Hoguin <[email protected]> | 2018-11-03 18:55:40 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2018-11-03 18:55:40 +0100 |
commit | be09711687218070ee670be7d549df8338b4ae92 (patch) | |
tree | 3fd0a125066b2d6eebbe4aee6190e426771c2ee4 /src/cowboy_http2.erl | |
parent | 571719a164326eebdc792b43170fe27f123aac0d (diff) | |
download | cowboy-be09711687218070ee670be7d549df8338b4ae92.tar.gz cowboy-be09711687218070ee670be7d549df8338b4ae92.tar.bz2 cowboy-be09711687218070ee670be7d549df8338b4ae92.zip |
Add an option to disable sendfile for a listener
Diffstat (limited to 'src/cowboy_http2.erl')
-rw-r--r-- | src/cowboy_http2.erl | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/cowboy_http2.erl b/src/cowboy_http2.erl index a1dd93e..d461595 100644 --- a/src/cowboy_http2.erl +++ b/src/cowboy_http2.erl @@ -44,6 +44,7 @@ middlewares => [module()], preface_timeout => timeout(), proxy_header => boolean(), + sendfile => boolean(), settings_timeout => timeout(), shutdown_timeout => timeout(), stream_handlers => [module()], @@ -650,10 +651,14 @@ send_data_frame(State=#state{socket=Socket, transport=Transport}, StreamID, IsFin, {data, Data}) -> Transport:send(Socket, cow_http2:data(StreamID, IsFin, Data)), State; -send_data_frame(State=#state{socket=Socket, transport=Transport}, +send_data_frame(State=#state{socket=Socket, transport=Transport, opts=Opts}, StreamID, IsFin, {sendfile, Offset, Bytes, Path}) -> Transport:send(Socket, cow_http2:data_header(StreamID, IsFin, Bytes)), - 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; %% The stream is terminated in cow_http2_machine:prepare_trailers. send_data_frame(State=#state{socket=Socket, transport=Transport, |