auto-generate Unicorn::Const::UNICORN_VERSION
[unicorn.git] / lib / unicorn / preread_input.rb
blob12eb3e8b446e72743db5645e0e8a54af3de932af
1 # -*- encoding: binary -*-
3 module Unicorn
4 # This middleware is used to ensure input is buffered to memory
5 # or disk (depending on size) before the application is dispatched
6 # by entirely consuming it (from TeeInput) beforehand.
8 # Usage (in config.ru):
10 #     require 'unicorn/preread_input'
11 #     if defined?(Unicorn)
12 #       use Unicorn::PrereadInput
13 #     end
14 #     run YourApp.new
15 class PrereadInput
17   # :stopdoc:
18   def initialize(app)
19     @app = app
20   end
22   def call(env)
23     buf = ""
24     input = env["rack.input"]
25     if input.respond_to?(:rewind)
26       true while input.read(16384, buf)
27       input.rewind
28     end
29     @app.call(env)
30   end
31   # :startdoc:
32 end
33 end