diff options
Diffstat (limited to 'lib/unicorn/preread_input.rb')
-rw-r--r-- | lib/unicorn/preread_input.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/unicorn/preread_input.rb b/lib/unicorn/preread_input.rb new file mode 100644 index 0000000..12eb3e8 --- /dev/null +++ b/lib/unicorn/preread_input.rb @@ -0,0 +1,33 @@ +# -*- encoding: binary -*- + +module Unicorn +# 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 +class PrereadInput + + # :stopdoc: + def initialize(app) + @app = app + end + + 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 + # :startdoc: +end +end |