From de3bcfe3ba9402bd510f7414df1763b6b99dae47 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 3 May 2010 17:56:00 -0700 Subject: cleanup request size limiting for TeeInput users WAvoid mucking with Unicorn::TeeInput, since other apps may depend on that class, so we subclass it as Rainbows::TeeInput and modify as necessary in worker processes. For Revactor, remove the special-cased Rainbows::Revactor::TeeInput class and instead emulate readpartial for Revactor sockets instead. --- lib/rainbows/max_body.rb | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'lib/rainbows/max_body.rb') diff --git a/lib/rainbows/max_body.rb b/lib/rainbows/max_body.rb index 71141c1..ca63ea4 100644 --- a/lib/rainbows/max_body.rb +++ b/lib/rainbows/max_body.rb @@ -7,7 +7,7 @@ module Rainbows # setting class MaxBody < Struct.new(:app) - # this is meant to be included in Unicorn::TeeInput (and derived + # this is meant to be included in Rainbows::TeeInput (and derived # classes) to limit body sizes module Limit Util = Unicorn::Util @@ -41,7 +41,7 @@ class MaxBody < Struct.new(:app) end def tee(length, dst) - rv = _tee(length, dst) + rv = super if rv && ((@max_body -= rv.size) < 0) # make HttpParser#keepalive? => false to force an immediate disconnect # after we write @@ -60,17 +60,10 @@ class MaxBody < Struct.new(:app) case G.server.use when :Rev, :EventMachine, :NeverBlock return - when :Revactor - Rainbows::Revactor::TeeInput - else - Unicorn::TeeInput - end.class_eval do - alias _tee tee # can't use super here :< - remove_method :tee - remove_method :initialize if G.server.use != :Revactor # FIXME CODE SMELL - include Limit end + TeeInput.class_eval { include Limit } + # force ourselves to the outermost middleware layer G.server.app = MaxBody.new(G.server.app) end -- cgit v1.2.3-24-ge0c7