From 06bf73975864b8e16ef1ee977f8424a0e5517fd6 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 1 Jul 2009 13:59:40 -0700 Subject: Force streaming input onto apps by default This change gives applications full control to deny clients from uploading unwanted message bodies. This also paves the way for doing things like upload progress notification within applications in a Rack::Lint-compatible manner. Since we don't support HTTP keepalive, so we have more freedom here by being able to close TCP connections and deny clients the ability to write to us (and thus wasting our bandwidth). While I could've left this feature off by default indefinitely for maximum backwards compatibility (for arguably broken applications), Unicorn is not and has never been about supporting the lowest common denominator. --- lib/unicorn/tee_input.rb | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'lib/unicorn/tee_input.rb') diff --git a/lib/unicorn/tee_input.rb b/lib/unicorn/tee_input.rb index 8dd8954..06028a6 100644 --- a/lib/unicorn/tee_input.rb +++ b/lib/unicorn/tee_input.rb @@ -29,22 +29,20 @@ module Unicorn @size = size # nil if chunked end - def consume - @input or return - buf = Z.dup - while tee(Const::CHUNK_SIZE, buf) - end - @tmp.rewind - self - end - # returns the size of the input. This is what the Content-Length # header value should be, and how large our input is expected to be. # For TE:chunked, this requires consuming all of the input stream # before returning since there's no other way def size @size and return @size - @input and consume + + if @input + buf = Z.dup + while tee(Const::CHUNK_SIZE, buf) + end + @tmp.rewind + end + @size = @tmp.stat.size end -- cgit v1.2.3-24-ge0c7