about summary refs log tree commit homepage
path: root/lib/rainbows/coolio
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-12-30 08:33:15 +0000
committerEric Wong <normalperson@yhbt.net>2011-01-04 16:37:42 -0800
commite21939d776673b2f8887adf7a5c64812b7d2e98e (patch)
tree48aa3a71201e770758bd09b325c3f2704411af7f /lib/rainbows/coolio
parent4a76da1833922c74e147be5def9bfe04fd0c16a2 (diff)
downloadrainbows-e21939d776673b2f8887adf7a5c64812b7d2e98e.tar.gz
Rack::Utils::HeaderHash is still very expensive in Rack 1.2,
especially for simple things that we want to run as fast as
possible with minimal interference.  HeaderHash is unnecessary
for most requests that do not send Content-Range in responses.
Diffstat (limited to 'lib/rainbows/coolio')
-rw-r--r--lib/rainbows/coolio/client.rb28
1 files changed, 13 insertions, 15 deletions
diff --git a/lib/rainbows/coolio/client.rb b/lib/rainbows/coolio/client.rb
index 6360e2d..d0b17a9 100644
--- a/lib/rainbows/coolio/client.rb
+++ b/lib/rainbows/coolio/client.rb
@@ -84,39 +84,37 @@ class Rainbows::Coolio::Client < Coolio::IO
   end
 
   # used for streaming sockets and pipes
-  def stream_response(status, headers, io, body)
-    c = stream_response_headers(status, headers) if headers
+  def stream_response_body(body, io, chunk)
     # we only want to attach to the Coolio::Loop belonging to the
     # main thread in Ruby 1.9
-    io = (c ? ResponseChunkPipe : ResponsePipe).new(io, self, body)
+    io = (chunk ? ResponseChunkPipe : ResponsePipe).new(io, self, body)
     defer_body(io.attach(LOOP))
   end
 
   def coolio_write_response(response, alive)
     status, headers, body = response
-    headers = @hp.headers? ? HH.new(headers) : nil
 
-    headers[CONNECTION] = alive ? KEEP_ALIVE : CLOSE if headers
     if body.respond_to?(:to_path)
       io = body_to_io(body)
       st = io.stat
 
       if st.file?
-        offset, count = 0, st.size
-        if headers
-          if range = make_range!(@env, status, headers)
-            status, offset, count = range
-          end
-          write(response_header(status, headers))
+        if respond_to?(:sendfile_range) && r = sendfile_range(status, headers)
+          status, headers, range = r
+          write_headers(status, headers, alive)
+          defer_body(SF.new(range[0], range[1], io, body)) if range
+        else
+          write_headers(status, headers, alive)
+          defer_body(SF.new(0, st.size, io, body))
         end
-        return defer_body(SF.new(offset, count, io, body))
+        return
       elsif st.socket? || st.pipe?
-        return stream_response(status, headers, io, body)
+        chunk = stream_response_headers(status, headers, alive)
+        return stream_response_body(body, io, chunk)
       end
       # char or block device... WTF? fall through to body.each
     end
-    write(response_header(status, headers)) if headers
-    write_body_each(self, body, nil)
+    write_response(status, headers, body, alive)
   end
 
   def app_call