about summary refs log tree commit homepage
path: root/lib/rainbows
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-12-07 12:11:51 -0800
committerEric Wong <normalperson@yhbt.net>2010-12-08 13:32:44 -0800
commit1562a19a021a72a78ba495328d2d37ba0dc83b8c (patch)
treee86a23ed6484678936d57c1794980609069eafd0 /lib/rainbows
parentb4835c6d542c6369f2523ab68fc41b0202d7c6dc (diff)
downloadrainbows-1562a19a021a72a78ba495328d2d37ba0dc83b8c.tar.gz
Large uploads behave differently with regard to buffering,
and there were bugs in the way the Rev and Revactor backends
handled uploads.
Diffstat (limited to 'lib/rainbows')
-rw-r--r--lib/rainbows/ev_core.rb2
-rw-r--r--lib/rainbows/revactor.rb8
2 files changed, 9 insertions, 1 deletions
diff --git a/lib/rainbows/ev_core.rb b/lib/rainbows/ev_core.rb
index 8241584..46fdedf 100644
--- a/lib/rainbows/ev_core.rb
+++ b/lib/rainbows/ev_core.rb
@@ -86,6 +86,8 @@ module Rainbows::EvCore
         @hp.filter_body(@buf2, @buf << data)
         @input << @buf2
         on_read("")
+      else
+        want_more
       end
     when :trailers
       if @hp.trailers(@env, @buf << data)
diff --git a/lib/rainbows/revactor.rb b/lib/rainbows/revactor.rb
index 59f37b0..51f6c1f 100644
--- a/lib/rainbows/revactor.rb
+++ b/lib/rainbows/revactor.rb
@@ -46,13 +46,14 @@ module Rainbows::Revactor
     alive = false
 
     begin
+      ts = nil
       until env = hp.parse
         buf << client.read(*rd_args)
       end
 
       env[CLIENT_IO] = client
       env[RACK_INPUT] = 0 == hp.content_length ?
-               NULL_IO : Unicorn::TeeInput.new(TeeSocket.new(client), hp)
+               NULL_IO : Unicorn::TeeInput.new(ts = TeeSocket.new(client), hp)
       env[REMOTE_ADDR] = remote_addr
       status, headers, body = app.call(env.update(RACK_DEFAULTS))
 
@@ -68,6 +69,7 @@ module Rainbows::Revactor
         alive = hp.next? && G.alive && G.kato > 0
         headers[CONNECTION] = alive ? KEEP_ALIVE : CLOSE
         client.write(response_header(status, headers))
+        alive && ts and buf << ts.leftover
       end
       write_body(client, body, range)
     end while alive
@@ -155,6 +157,10 @@ module Rainbows::Revactor
       @socket, @rbuf = socket, IO::Buffer.new
     end
 
+    def leftover
+      @rbuf.read
+    end
+
     # Revactor socket reads always return an unspecified amount,
     # sometimes too much
     def kgio_read(length, dst = "")