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-20 17:48:58 -0700
committerEric Wong <normalperson@yhbt.net>2010-10-21 00:49:36 +0000
commitd4a2b5dd2b85f4b2d3bb120ee1e1b0dde31bc25c (patch)
tree85866cc775a213216701ccaedf16061f15d13975 /lib/rainbows/max_body.rb
parenta085ba3586756ac1f778d2862f75889de2449b0e (diff)
We get basic internal API changes from Unicorn,
code simplifications coming next.
Diffstat (limited to 'lib/rainbows/max_body.rb')
-rw-r--r--lib/rainbows/max_body.rb38
1 files changed, 19 insertions, 19 deletions
diff --git a/lib/rainbows/max_body.rb b/lib/rainbows/max_body.rb
index 23e4fa6..d825d2f 100644
--- a/lib/rainbows/max_body.rb
+++ b/lib/rainbows/max_body.rb
@@ -11,32 +11,32 @@ class MaxBody < Struct.new(:app)
   # this is meant to be included in Rainbows::TeeInput (and derived
   # classes) to limit body sizes
   module Limit
-    Util = Unicorn::Util
+    TmpIO = Unicorn::TmpIO
 
-    def initialize(socket, req, parser, buf)
-      self.len = parser.content_length
+    def initialize(socket, request)
+      @parser = request
+      @buf = request.buf
+      @env = request.env
+      @len = request.content_length
 
       max = Rainbows.max_bytes # never nil, see MaxBody.setup
-      if len && len > max
+      if @len && @len > max
         socket.write(Const::ERROR_413_RESPONSE)
         socket.close
-        raise IOError, "Content-Length too big: #{len} > #{max}", []
+        raise IOError, "Content-Length too big: #@len > #{max}", []
       end
 
-      self.req = req
-      self.parser = parser
-      self.buf = buf
-      self.socket = socket
-      self.buf2 = ""
-      if buf.size > 0
-        parser.filter_body(buf2, buf) and finalize_input
-        buf2.size > max and raise IOError, "chunked request body too big", []
+      @socket = socket
+      @buf2 = ""
+      if @buf.size > 0
+        parser.filter_body(@buf2, @buf) and finalize_input
+        @buf2.size > max and raise IOError, "chunked request body too big", []
       end
-      self.tmp = len && len < Const::MAX_BODY ? StringIO.new("") : Util.tmpio
-      if buf2.size > 0
-        tmp.write(buf2)
-        tmp.seek(0)
-        max -= buf2.size
+      @tmp = @len && @len < Const::MAX_BODY ? StringIO.new("") : TmpIO.new
+      if @buf2.size > 0
+        @tmp.write(@buf2)
+        @tmp.rewind
+        max -= @buf2.size
       end
       @max_body = max
     end
@@ -46,7 +46,7 @@ class MaxBody < Struct.new(:app)
       if rv && ((@max_body -= rv.size) < 0)
         # make HttpParser#keepalive? => false to force an immediate disconnect
         # after we write
-        parser.reset
+        @parser.reset
         throw :rainbows_EFBIG
       end
       rv