Sha256: 935fab7e8927818810a1a1b99f3466104e4a708c270cf09f82b1b47a37bc15cc

Contents?: true

Size: 688 Bytes

Versions: 9

Compression:

Stored size: 688 Bytes

Contents

# frozen_string_literal: true

require 'rack/body_proxy'

module Rack

  # Middleware tracks and cleans Tempfiles created throughout a request (i.e. Rack::Multipart)
  # Ideas/strategy based on posts by Eric Wong and Charles Oliver Nutter
  # https://groups.google.com/forum/#!searchin/rack-devel/temp/rack-devel/brK8eh-MByw/sw61oJJCGRMJ
  class TempfileReaper
    def initialize(app)
      @app = app
    end

    def call(env)
      env[RACK_TEMPFILES] ||= []
      status, headers, body = @app.call(env)
      body_proxy = BodyProxy.new(body) do
        env[RACK_TEMPFILES].each(&:close!) unless env[RACK_TEMPFILES].nil?
      end
      [status, headers, body_proxy]
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rack-2.1.4.4 lib/rack/tempfile_reaper.rb
rack-2.1.4.3 lib/rack/tempfile_reaper.rb
rack-2.1.4.2 lib/rack/tempfile_reaper.rb
rack-2.1.4.1 lib/rack/tempfile_reaper.rb
rack-2.1.4 lib/rack/tempfile_reaper.rb
rack-2.1.3 lib/rack/tempfile_reaper.rb
rack-2.1.2 lib/rack/tempfile_reaper.rb
rack-2.1.1 lib/rack/tempfile_reaper.rb
rack-2.1.0 lib/rack/tempfile_reaper.rb