From 180485d49ea858f83ef2a28a9e07224aa514edc7 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 22 Oct 2010 16:21:03 -0700 Subject: unindent most files This simplifies and disambiguates most constant resolution issues as well as lowering our identation level. Hopefully this makes code easier to understand. --- lib/rainbows/max_body.rb | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'lib/rainbows/max_body.rb') diff --git a/lib/rainbows/max_body.rb b/lib/rainbows/max_body.rb index d825d2f..223c57e 100644 --- a/lib/rainbows/max_body.rb +++ b/lib/rainbows/max_body.rb @@ -1,17 +1,17 @@ # -*- encoding: binary -*- # :enddoc: -module Rainbows # middleware used to enforce client_max_body_size for TeeInput users, # there is no need to configure this middleware manually, it will # automatically be configured for you based on the client_max_body_size # setting -class MaxBody < Struct.new(:app) +class Rainbows::MaxBody < Struct.new(:app) # this is meant to be included in Rainbows::TeeInput (and derived # classes) to limit body sizes module Limit TmpIO = Unicorn::TmpIO + MAX_BODY = Rainbows::Const::MAX_BODY def initialize(socket, request) @parser = request @@ -21,7 +21,7 @@ class MaxBody < Struct.new(:app) max = Rainbows.max_bytes # never nil, see MaxBody.setup if @len && @len > max - socket.write(Const::ERROR_413_RESPONSE) + socket.write(Rainbows::Const::ERROR_413_RESPONSE) socket.close raise IOError, "Content-Length too big: #@len > #{max}", [] end @@ -32,7 +32,7 @@ class MaxBody < Struct.new(:app) parser.filter_body(@buf2, @buf) and finalize_input @buf2.size > max and raise IOError, "chunked request body too big", [] end - @tmp = @len && @len < Const::MAX_BODY ? StringIO.new("") : TmpIO.new + @tmp = @len && @len < MAX_BODY ? StringIO.new("") : TmpIO.new if @buf2.size > 0 @tmp.write(@buf2) @tmp.rewind @@ -58,15 +58,15 @@ class MaxBody < Struct.new(:app) # if it's reconfigured def self.setup Rainbows.max_bytes or return - case G.server.use + case Rainbows::G.server.use when :Rev, :EventMachine, :NeverBlock return end - TeeInput.class_eval { include Limit } + Rainbows::TeeInput.__send__(:include, Limit) # force ourselves to the outermost middleware layer - G.server.app = MaxBody.new(G.server.app) + Rainbows::G.server.app = self.new(Rainbows::G.server.app) end # Rack response returned when there's an error @@ -78,6 +78,4 @@ class MaxBody < Struct.new(:app) def call(env) catch(:rainbows_EFBIG) { app.call(env) } || err(env) end - -end # class -end # module +end -- cgit v1.2.3-24-ge0c7