about summary refs log tree commit homepage
path: root/lib/rainbows/event_machine.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-06-06 02:14:58 +0000
committerEric Wong <normalperson@yhbt.net>2010-06-06 02:14:58 +0000
commitb1315983056f91467b336aeb426759debc006a4e (patch)
tree8a0d3dee51038b567dcb72bd4af40d5ff707da9d /lib/rainbows/event_machine.rb
parent6ada0eb9916bbcebbcf2af843c1f5fb11904caee (diff)
downloadrainbows-b1315983056f91467b336aeb426759debc006a4e.tar.gz
centralize body => IO conversion logic
Since EventMachine and Rev shared the same logic for optimizing
and avoiding extra file opens for IO/File-ish response bodies,
so centralize that.

For Ruby 1.9 users, we've also enabled this logic so ThreadPool,
ThreadSpawn, WriterThreadPool, and WriterThreadSpawn can take
advantage of Rainbows::DevFdResponse-generated bodies while
proxying sockets.
Diffstat (limited to 'lib/rainbows/event_machine.rb')
-rw-r--r--lib/rainbows/event_machine.rb9
1 files changed, 3 insertions, 6 deletions
diff --git a/lib/rainbows/event_machine.rb b/lib/rainbows/event_machine.rb
index b19bdec..12d9e5e 100644
--- a/lib/rainbows/event_machine.rb
+++ b/lib/rainbows/event_machine.rb
@@ -112,18 +112,15 @@ module Rainbows
         end
 
         headers = Rack::Utils::HeaderHash.new(response[1])
-        path = body.to_path
-        io = body.to_io if body.respond_to?(:to_io)
-        io ||= IO.new($1.to_i) if path =~ %r{\A/dev/fd/(\d+)\z}
-        io ||= File.open(path, 'rb') # could be a named pipe
-
+        io = Rainbows.body_to_io(body)
         st = io.stat
+
         if st.file?
           headers.delete('Transfer-Encoding')
           headers['Content-Length'] ||= st.size.to_s
           response = [ response.first, headers.to_hash, [] ]
           HttpResponse.write(self, response, out)
-          stream = stream_file_data(path)
+          stream = stream_file_data(body.to_path)
           stream.callback { quit } unless alive
         elsif st.socket? || st.pipe?
           do_chunk = !!(headers['Transfer-Encoding'] =~ %r{\Achunked\z}i)