about summary refs log tree commit homepage
path: root/lib/rainbows/rev
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rainbows/rev')
-rw-r--r--lib/rainbows/rev/client.rb15
-rw-r--r--lib/rainbows/rev/deferred_response.rb2
2 files changed, 8 insertions, 9 deletions
diff --git a/lib/rainbows/rev/client.rb b/lib/rainbows/rev/client.rb
index f067d1b..5c61109 100644
--- a/lib/rainbows/rev/client.rb
+++ b/lib/rainbows/rev/client.rb
@@ -52,6 +52,10 @@ module Rainbows
         schedule_write
       end
 
+      def next
+        @deferred_bodies.shift
+      end
+
       def timeout?
         @_write_buffer.empty? && @deferred_bodies.empty? and close.nil?
       end
@@ -69,25 +73,20 @@ module Rainbows
         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?
-            if headers
-              headers[CONNECTION] = alive ? KEEP_ALIVE : CLOSE
-              write(response_header(status, headers))
-            end
+            write(response_header(status, headers)) if headers
             return defer_body(to_sendfile(io))
           elsif st.socket? || st.pipe?
             return stream_response(status, headers, io, body)
           end
           # char or block device... WTF? fall through to body.each
         end
-        if headers
-          headers[CONNECTION] = alive ? KEEP_ALIVE : CLOSE
-          write(response_header(status, headers))
-        end
+        write(response_header(status, headers)) if headers
         write_body_each(self, body)
       end
 
diff --git a/lib/rainbows/rev/deferred_response.rb b/lib/rainbows/rev/deferred_response.rb
index de348bb..cc4ea10 100644
--- a/lib/rainbows/rev/deferred_response.rb
+++ b/lib/rainbows/rev/deferred_response.rb
@@ -20,7 +20,7 @@ module Rainbows
 
       def on_close
         @do_chunk and @client.write("0\r\n\r\n")
-        @client.quit
+        @client.next
         @body.respond_to?(:close) and @body.close
       end
     end # class DeferredResponse