diff options
Diffstat (limited to 'lib/rainbows/response.rb')
-rw-r--r-- | lib/rainbows/response.rb | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/lib/rainbows/response.rb b/lib/rainbows/response.rb index 65599e9..fac2c0e 100644 --- a/lib/rainbows/response.rb +++ b/lib/rainbows/response.rb @@ -6,6 +6,7 @@ module Rainbows::Response KeepAlive = "keep-alive" Content_Length = "Content-Length".freeze Transfer_Encoding = "Transfer-Encoding".freeze + Rainbows.config!(self, :copy_stream) # private file class for IO objects opened by Rainbows! itself (and not # the app or middleware) @@ -67,7 +68,7 @@ module Rainbows::Response end # generic response writer, used for most dynamically-generated responses - # and also when IO.copy_stream and/or IO#trysendfile is unavailable + # and also when copy_stream and/or IO#trysendfile is unavailable def write_response(status, headers, body, alive) write_headers(status, headers, alive) write_body_each(body) @@ -89,29 +90,29 @@ module Rainbows::Response include Sendfile end - if IO.respond_to?(:copy_stream) + if COPY_STREAM unless IO.method_defined?(:trysendfile) module CopyStream def write_body_file(body, range) - range ? IO.copy_stream(body, self, range[1], range[0]) : - IO.copy_stream(body, self, nil, 0) + range ? COPY_STREAM.copy_stream(body, self, range[1], range[0]) : + COPY_STREAM.copy_stream(body, self, nil, 0) end end include CopyStream end - # write_body_stream is an alias for write_body_each if IO.copy_stream + # write_body_stream is an alias for write_body_each if copy_stream # isn't used or available. def write_body_stream(body) - IO.copy_stream(io = body_to_io(body), self) + COPY_STREAM.copy_stream(io = body_to_io(body), self) ensure close_if_private(io) end - else # ! IO.respond_to?(:copy_stream) + else # ! COPY_STREAM alias write_body_stream write_body_each - end # ! IO.respond_to?(:copy_stream) + end # ! COPY_STREAM - if IO.method_defined?(:trysendfile) || IO.respond_to?(:copy_stream) + if IO.method_defined?(:trysendfile) || COPY_STREAM HTTP_RANGE = 'HTTP_RANGE' Content_Range = 'Content-Range'.freeze @@ -181,5 +182,5 @@ module Rainbows::Response end end include ToPath - end # IO.respond_to?(:copy_stream) || IO.method_defined?(:trysendfile) + end # COPY_STREAM || IO.method_defined?(:trysendfile) end |