about summary refs log tree commit homepage
path: root/lib/yahns/http_context.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/yahns/http_context.rb')
-rw-r--r--lib/yahns/http_context.rb19
1 files changed, 10 insertions, 9 deletions
diff --git a/lib/yahns/http_context.rb b/lib/yahns/http_context.rb
index 1554086..8393ffe 100644
--- a/lib/yahns/http_context.rb
+++ b/lib/yahns/http_context.rb
@@ -77,14 +77,15 @@ module Yahns::HttpContext # :nodoc:
     @app_defaults["rack.errors"]
   end
 
-  def tmpio_for(len)
-    if len # Content-Length given
-      len <= @client_body_buffer_size ? StringIO.new("")
-           : Yahns::TmpIO.new(@input_buffer_tmpdir)
-    else # chunked, unknown length
-      mbs = @client_max_body_size
-      tmpdir = @input_buffer_tmpdir
-      mbs ? Yahns::CapInput.new(mbs, tmpdir) : Yahns::TmpIO.new(tmpdir)
-    end
+  def tmpio_for(len, env)
+    # short requests are most common
+    return StringIO.new('') if len && len <= @client_body_buffer_size;
+
+    # too big or chunked, unknown length
+    tmp = @input_buffer_tmpdir
+    mbs = @client_max_body_size
+    tmp = mbs ? Yahns::CapInput.new(mbs, tmp) : Yahns::TmpIO.new(tmp)
+    (env['rack.tempfiles'] ||= []) << tmp
+    tmp
   end
 end