about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-07-20 05:18:48 +0000
committerEric Wong <normalperson@yhbt.net>2010-07-20 05:21:32 +0000
commit015daa81f26afc59d1da857b8bbedfb80eb532b1 (patch)
tree58e2feb479ac97e7733204ccd82889640bcf09d9 /lib
parentafb7e51363c646751be1a12083c1c7b184e3fd47 (diff)
downloadrainbows-015daa81f26afc59d1da857b8bbedfb80eb532b1.tar.gz
This is cheaper for serving static files and only
slightly more expensive for pipes and sockets (extra
path lookup for File.stat).
Diffstat (limited to 'lib')
-rw-r--r--lib/rainbows/event_machine.rb7
1 files changed, 3 insertions, 4 deletions
diff --git a/lib/rainbows/event_machine.rb b/lib/rainbows/event_machine.rb
index 8de02ea..4402c72 100644
--- a/lib/rainbows/event_machine.rb
+++ b/lib/rainbows/event_machine.rb
@@ -115,8 +115,7 @@ module Rainbows
           headers[CONNECTION] = CLOSE if headers
           alive = true
         elsif body.respond_to?(:to_path)
-          io = body_to_io(body)
-          st = io.stat
+          st = File.stat(path = body.to_path)
 
           if st.file?
             cb = lambda do
@@ -124,11 +123,11 @@ module Rainbows
               quit unless alive
             end
             write(response_header(status, headers)) if headers
-            io.close
-            @body = stream = stream_file_data(body.to_path)
+            @body = stream = stream_file_data(path)
             stream.errback(&cb)
             return stream.callback(&cb)
           elsif st.socket? || st.pipe?
+            io = body_to_io(body)
             chunk = stream_response_headers(status, headers) if headers
             m = chunk ? ResponseChunkPipe : ResponsePipe
             return EM.watch(io, m, self, alive, body).notify_readable = true