about summary refs log tree commit homepage
path: root/lib/rainbows/max_body.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-10-22 16:21:03 -0700
committerEric Wong <normalperson@yhbt.net>2010-10-22 16:21:03 -0700
commit180485d49ea858f83ef2a28a9e07224aa514edc7 (patch)
treeb4c649d2118c0010bf3876a49dadfe3e4cbc3f86 /lib/rainbows/max_body.rb
parent41145ed4d335718ac43aec9313b7571a12fe96ee (diff)
downloadrainbows-180485d49ea858f83ef2a28a9e07224aa514edc7.tar.gz
This simplifies and disambiguates most constant resolution
issues as well as lowering our identation level.  Hopefully
this makes code easier to understand.
Diffstat (limited to 'lib/rainbows/max_body.rb')
-rw-r--r--lib/rainbows/max_body.rb18
1 files changed, 8 insertions, 10 deletions
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