Class: Unicorn::PrereadInput

Inherits:
Object
  • Object
show all
Defined in:
lib/unicorn/preread_input.rb

Overview

This middleware is used to ensure input is buffered to memory or disk (depending on size) before the application is dispatched by entirely consuming it (from TeeInput) beforehand.

Usage (in config.ru):

require 'unicorn/preread_input'
if defined?(Unicorn)
  use Unicorn::PrereadInput
end
run YourApp.new

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ PrereadInput

:stopdoc:


18
19
20
# File 'lib/unicorn/preread_input.rb', line 18

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object


22
23
24
25
26
27
28
29
30
# File 'lib/unicorn/preread_input.rb', line 22

def call(env)
  buf = ""
  input = env["rack.input"]
  if input.respond_to?(:rewind)
    true while input.read(16384, buf)
    input.rewind
  end
  @app.call(env)
end