about summary refs log tree commit homepage
path: root/lib/rainbows/http_parser.rb
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-11-14 02:47:21 +0000
committerEric Wong <e@80x24.org>2015-11-18 02:20:20 +0000
commit5d1e2f0ada7d63ad539bac7597d27ef2c4de2cdd (patch)
tree99637aa9d8bd445f4436a6fa78b5c4d25fc9b572 /lib/rainbows/http_parser.rb
parent3706ec9dce706d8cde76cafff1f3a24776435830 (diff)
downloadrainbows-5d1e2f0ada7d63ad539bac7597d27ef2c4de2cdd.tar.gz
unicorn 5 dropped support for this, essentially allowing unlimited
persistent connections if we used the parser as-is.
Since most of our concurrency models cannot handle infinite
persistent connections without being vulnerable to DoS,
we must support keepalive_requests like nginx does.
Diffstat (limited to 'lib/rainbows/http_parser.rb')
-rw-r--r--lib/rainbows/http_parser.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/rainbows/http_parser.rb b/lib/rainbows/http_parser.rb
index ec55fe9..30a67cb 100644
--- a/lib/rainbows/http_parser.rb
+++ b/lib/rainbows/http_parser.rb
@@ -2,6 +2,21 @@
 # :enddoc:
 # avoid modifying Unicorn::HttpParser
 class Rainbows::HttpParser < Unicorn::HttpParser
+  @keepalive_requests = 100
+  class << self
+    attr_accessor :keepalive_requests
+  end
+
+  def initialize(*args)
+    @keepalive_requests = self.class.keepalive_requests
+    super
+  end
+
+  def next?
+    return false if (@keepalive_requests -= 1) <= 0
+    super
+  end
+
   def self.quit
     alias_method :next?, :never!
   end