From d9c97a2e04e0455e2d2aa3e5ec6439c3b97a1b7c Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 23 Apr 2009 18:35:26 -0700 Subject: Fix data corruption with small uploads via browsers StringIO.new(partial_body) does not update the offset for new writes. So instead create the StringIO object and then syswrite to it and try to follow the same code path used by large uploads which use Tempfiles. --- lib/unicorn/http_request.rb | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/unicorn/http_request.rb b/lib/unicorn/http_request.rb index 9be3b11..0de496f 100644 --- a/lib/unicorn/http_request.rb +++ b/lib/unicorn/http_request.rb @@ -96,15 +96,10 @@ module Unicorn remain = content_length - http_body.length # must read more data to complete body - if remain < Const::MAX_BODY - # small body, just use that - @body = StringIO.new(http_body) - else # huge body, put it in a tempfile - @body = Tempfile.new(Const::UNICORN_TMP_BASE) - @body.binmode - @body.sync = true - @body.syswrite(http_body) - end + @body = remain < Const::MAX_BODY ? StringIO.new : Tempfile.new('') + @body.binmode + @body.sync = true + @body.syswrite(http_body) # Some clients (like FF1.0) report 0 for body and then send a body. # This will probably truncate them but at least the request goes through -- cgit v1.2.3-24-ge0c7