diff options
author | Eric Wong <normalperson@yhbt.net> | 2011-05-16 19:04:06 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2011-05-16 19:34:52 +0000 |
commit | 39f625fff05d457b01f088017f463a86d3b6c626 (patch) | |
tree | eae2a3a759b70e0f6d12caefdf177d3eca418efe /lib/rainbows/response.rb | |
parent | d520222050ce88388ae5e446c63642d79cc9796e (diff) | |
download | rainbows-39f625fff05d457b01f088017f463a86d3b6c626.tar.gz |
This allows using IO::Splice.copy_stream from the "io_splice" RubyGem on recent Linux systems. This also allows users to disable copy_stream usage entirely and use traditional response_body.each calls which are compatible with all Rack servers (to workaround bugs in IO.copy_stream under 1.9.2-p180).
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 |