diff options
author | Eric Wong <e@80x24.org> | 2015-04-24 02:38:15 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2015-04-24 03:00:25 +0000 |
commit | 3bdf5481e49d76b4502c51e5bdd93f68bfd1f0b4 (patch) | |
tree | ed15a24ca7fc52358e30c423269de665357114cc /lib | |
parent | 548e1e67d314f6ebd17df37ece0ee20632462f6f (diff) | |
download | unicorn-3bdf5481e49d76b4502c51e5bdd93f68bfd1f0b4.tar.gz |
Rack::TempfileReaper was added in rack 1.6 to cleanup temporary files. Make Unicorn::TmpIO ducktype-compatible so Rack::TempfileReaper may be used to free up space used by temporary buffer files. Ref: <CY1PR0301MB078011EB5A22B733EB222A45A4EE0@CY1PR0301MB0780.namprd03.prod.outlook.com> Reported-by: Mike Mulvaney <MMulvaney@bna.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/unicorn/tee_input.rb | 9 | ||||
-rw-r--r-- | lib/unicorn/tmpio.rb | 3 |
2 files changed, 11 insertions, 1 deletions
diff --git a/lib/unicorn/tee_input.rb b/lib/unicorn/tee_input.rb index 637c583..3c6d18a 100644 --- a/lib/unicorn/tee_input.rb +++ b/lib/unicorn/tee_input.rb @@ -28,13 +28,20 @@ class Unicorn::TeeInput < Unicorn::StreamInput @@client_body_buffer_size end + # for Rack::TempfileReaper in rack 1.6+ + def new_tmpio # :nodoc: + tmpio = Unicorn::TmpIO.new + (@parser.env['rack.tempfiles'] ||= []) << tmpio + tmpio + end + # Initializes a new TeeInput object. You normally do not have to call # this unless you are writing an HTTP server. def initialize(socket, request) @len = request.content_length super @tmp = @len && @len <= @@client_body_buffer_size ? - StringIO.new("") : Unicorn::TmpIO.new + StringIO.new("") : new_tmpio end # :call-seq: diff --git a/lib/unicorn/tmpio.rb b/lib/unicorn/tmpio.rb index 2da05a2..dcdf9da 100644 --- a/lib/unicorn/tmpio.rb +++ b/lib/unicorn/tmpio.rb @@ -26,4 +26,7 @@ class Unicorn::TmpIO < File def size stat.size end unless File.method_defined?(:size) + + # pretend we're Tempfile for Rack::TempfileReaper + alias close! close end |