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.rb20
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/yahns/http_context.rb b/lib/yahns/http_context.rb
index 605989f..bd455bd 100644
--- a/lib/yahns/http_context.rb
+++ b/lib/yahns/http_context.rb
@@ -18,6 +18,8 @@ module Yahns::HttpContext # :nodoc:
   attr_accessor :queue # set right before spawning acceptors
   attr_reader :app
   attr_reader :app_defaults
+  attr_writer :input_buffer_tmpdir
+  attr_writer :output_buffer_tmpdir
 
   def http_ctx_init(yahns_rack)
     @yahns_rack = yahns_rack
@@ -32,6 +34,10 @@ module Yahns::HttpContext # :nodoc:
     @client_timeout = 15
     @qegg = nil
     @queue = nil
+
+    # Dir.tmpdir can change while running, so leave these as nil
+    @input_buffer_tmpdir = nil
+    @output_buffer_tmpdir = nil
   end
 
   # call this after forking
@@ -74,10 +80,20 @@ module Yahns::HttpContext # :nodoc:
 
   def tmpio_for(len)
     if len # Content-Length given
-      len <= @client_body_buffer_size ? StringIO.new("") : Yahns::TmpIO.new
+      len <= @client_body_buffer_size ? StringIO.new("")
+           : Yahns::TmpIO.new(input_buffer_tmpdir)
     else # chunked, unknown length
       mbs = @client_max_body_size
-      mbs ? Yahns::CapInput.new(mbs) : Yahns::TmpIO.new
+      tmpdir = input_buffer_tmpdir
+      mbs ? Yahns::CapInput.new(mbs, tmpdir) : Yahns::TmpIO.new(tmpdir)
     end
   end
+
+  def input_buffer_tmpdir
+    @input_buffer_tmpdir || Dir.tmpdir
+  end
+
+  def output_buffer_tmpdir
+    @output_buffer_tmpdir || Dir.tmpdir
+  end
 end