From 98819daf5c638fec4d20bb3960e0d3188e772ab8 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 13 Oct 2015 23:45:59 +0000 Subject: response: convert source arg to path before IO.copy_stream This will allow us use the sendfile syscall under Linux on Ruby which favor #read/#readpartial methods for non-IO objects. This also allows us to revert changes made in commit db790ff3531acdfa23ab290998bba29360a6782b ("sync_close: This fix breakage from Ruby-trunk r50118") --- lib/rainbows/response.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib/rainbows/response.rb') diff --git a/lib/rainbows/response.rb b/lib/rainbows/response.rb index 8d0de1d..b7b6aa8 100644 --- a/lib/rainbows/response.rb +++ b/lib/rainbows/response.rb @@ -128,6 +128,11 @@ module Rainbows::Response unless IO.method_defined?(:trysendfile) module CopyStream def write_body_file(body, range) + # ensure sendfile gets used for SyncClose objects: + if !body.kind_of?(IO) && body.respond_to?(:to_path) + body = body.to_path + end + range ? COPY_STREAM.copy_stream(body, self, range[1], range[0]) : COPY_STREAM.copy_stream(body, self) end -- cgit v1.2.3-24-ge0c7