reimplement client_max_body_size handlers
[rainbows.git] / lib / rainbows / max_body / wrapper.rb
blob3c38ca67abe5be8114846bcaf30aacc39635b569
1 # -*- encoding: binary -*-
2 # :enddoc:
3 class Rainbows::MaxBody::Wrapper
4   def initialize(rack_input, limit)
5     @input, @limit = rack_input, limit
6   end
8   def check(rv)
9     throw :rainbows_EFBIG if rv && ((@limit -= rv.size) < 0)
10     rv
11   end
13   def each(&block)
14     while line = @input.gets
15       yield check(line)
16     end
17   end
19   def read(*args)
20     check(@input.read(*args))
21   end
23   def gets
24     check(@input.gets)
25   end
26 end