diff options
Diffstat (limited to 'lib/yahns')
-rw-r--r-- | lib/yahns/http_client.rb | 2 | ||||
-rw-r--r-- | lib/yahns/http_context.rb | 19 | ||||
-rw-r--r-- | lib/yahns/tee_input.rb | 2 | ||||
-rw-r--r-- | lib/yahns/tmpio.rb | 3 |
4 files changed, 15 insertions, 11 deletions
diff --git a/lib/yahns/http_client.rb b/lib/yahns/http_client.rb index a0fd5a4..620e925 100644 --- a/lib/yahns/http_client.rb +++ b/lib/yahns/http_client.rb @@ -57,7 +57,7 @@ class Yahns::HttpClient < Kgio::Socket # :nodoc: "Content-Length:#{len} too large (>#{mbs})", [] end @state = :body - @input = k.tmpio_for(len) + @input = k.tmpio_for(len, @hs.env) rbuf = Thread.current[:yahns_rbuf] @hs.filter_body(rbuf, @hs.buf) 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 diff --git a/lib/yahns/tee_input.rb b/lib/yahns/tee_input.rb index 9028a6e..09933ca 100644 --- a/lib/yahns/tee_input.rb +++ b/lib/yahns/tee_input.rb @@ -19,7 +19,7 @@ class Yahns::TeeInput < Yahns::StreamInput # :nodoc: def initialize(client, request) @len = request.content_length super - @tmp = client.class.tmpio_for(@len) + @tmp = client.class.tmpio_for(@len, request.env) end # :call-seq: diff --git a/lib/yahns/tmpio.rb b/lib/yahns/tmpio.rb index ca86b4e..48832df 100644 --- a/lib/yahns/tmpio.rb +++ b/lib/yahns/tmpio.rb @@ -30,4 +30,7 @@ class Yahns::TmpIO < File # :nodoc: fp.sync = true fp end + + # pretend we're Tempfile for Rack::TempfileReaper + alias close! close end |