about summary refs log tree commit homepage
path: root/lib/rainbows
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-12-26 03:30:36 +0000
committerEric Wong <normalperson@yhbt.net>2010-12-26 09:53:30 +0000
commit7bfd7995fd403f80940e3f6ac36f9ae58b7040cb (patch)
treee5822c83d2e429d893461dc32d4f0478ea281525 /lib/rainbows
parent92a11cdfe00c5e551388c2cc1a62bfc59d568c6f (diff)
downloadrainbows-7bfd7995fd403f80940e3f6ac36f9ae58b7040cb.tar.gz
The HttpParser#next? method will come with keepalive protection
for Rainbows!, which can prevent clients from monopolizing a
server with excessive pipelining/keepalive requests.
Diffstat (limited to 'lib/rainbows')
-rw-r--r--lib/rainbows/event_machine.rb3
-rw-r--r--lib/rainbows/rev/client.rb3
-rw-r--r--lib/rainbows/rev/thread.rb3
3 files changed, 3 insertions, 6 deletions
diff --git a/lib/rainbows/event_machine.rb b/lib/rainbows/event_machine.rb
index 99fa32e..8029b1a 100644
--- a/lib/rainbows/event_machine.rb
+++ b/lib/rainbows/event_machine.rb
@@ -91,10 +91,9 @@ module Rainbows::EventMachine
       # long-running async response
       (response.nil? || -1 == response[0]) and return @state = :close
 
-      alive = @hp.keepalive? && G.alive && G.kato > 0
+      alive = @hp.next? && G.alive && G.kato > 0
       em_write_response(response, alive)
       if alive
-        @hp.reset
         @state = :headers
         if @buf.empty?
           set_comm_inactivity_timeout(G.kato)
diff --git a/lib/rainbows/rev/client.rb b/lib/rainbows/rev/client.rb
index b212f5c..8c39792 100644
--- a/lib/rainbows/rev/client.rb
+++ b/lib/rainbows/rev/client.rb
@@ -125,9 +125,8 @@ class Rainbows::Rev::Client < ::Rev::IO
     @env[REMOTE_ADDR] = @_io.kgio_addr
     response = APP.call(@env.update(RACK_DEFAULTS))
 
-    rev_write_response(response, alive = @hp.keepalive? && G.alive)
+    rev_write_response(response, alive = @hp.next? && G.alive)
     return quit unless alive && :close != @state
-    @hp.reset
     @state = :headers
     disable if enabled?
   end
diff --git a/lib/rainbows/rev/thread.rb b/lib/rainbows/rev/thread.rb
index 2356ae2..0f36ce5 100644
--- a/lib/rainbows/rev/thread.rb
+++ b/lib/rainbows/rev/thread.rb
@@ -20,11 +20,10 @@ module Rainbows
 
       # this is only called in the master thread
       def response_write(response)
-        alive = @hp.keepalive? && G.alive
+        alive = @hp.next? && G.alive
         rev_write_response(response, alive)
         return quit unless alive && :close != @state
 
-        @hp.reset
         @state = :headers
       end