diff options
author | Eric Wong <normalperson@yhbt.net> | 2010-11-16 16:16:42 -0800 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2010-11-16 16:21:33 -0800 |
commit | 31cf77e7aa2f2e6065e7ace44e55c3f042b51f1b (patch) | |
tree | 7dfd53c499cbf7a52165d3480d56d8576a743781 /lib/rainbows/max_body/wrapper.rb | |
parent | 42747db815ad668b20849afb2a9dcdd1319713ae (diff) | |
download | rainbows-31cf77e7aa2f2e6065e7ace44e55c3f042b51f1b.tar.gz |
This allows the client_max_body_size implementation to not rely on Unicorn::TeeInput internals, allowing it to be used with Unicorn::StreamInput (or any other (nearly) Rack::Lint-compatible input object).
Diffstat (limited to 'lib/rainbows/max_body/wrapper.rb')
-rw-r--r-- | lib/rainbows/max_body/wrapper.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/rainbows/max_body/wrapper.rb b/lib/rainbows/max_body/wrapper.rb new file mode 100644 index 0000000..3c38ca6 --- /dev/null +++ b/lib/rainbows/max_body/wrapper.rb @@ -0,0 +1,26 @@ +# -*- encoding: binary -*- +# :enddoc: +class Rainbows::MaxBody::Wrapper + def initialize(rack_input, limit) + @input, @limit = rack_input, limit + end + + def check(rv) + throw :rainbows_EFBIG if rv && ((@limit -= rv.size) < 0) + rv + end + + def each(&block) + while line = @input.gets + yield check(line) + end + end + + def read(*args) + check(@input.read(*args)) + end + + def gets + check(@input.gets) + end +end |