diff options
author | Mislav Marohnić <mislav.marohnic@gmail.com> | 2009-04-17 21:53:44 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2009-04-17 21:53:44 -0500 |
commit | 7ce0778a1516110cf8015e59e2e8fac15032379c (patch) | |
tree | 8efde4843152fc76d6d6eb010fb173b1f02af2f0 /actionpack/lib/action_dispatch/middleware/rewindable_input.rb | |
parent | 8423bb6a684fd68461faab87149a5bdfea61f43a (diff) | |
download | rails-7ce0778a1516110cf8015e59e2e8fac15032379c.tar.gz rails-7ce0778a1516110cf8015e59e2e8fac15032379c.tar.bz2 rails-7ce0778a1516110cf8015e59e2e8fac15032379c.zip |
Always buffer rack.input if it is not rewindable
Signed-off-by: Joshua Peek <josh@joshpeek.com>
Diffstat (limited to 'actionpack/lib/action_dispatch/middleware/rewindable_input.rb')
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/rewindable_input.rb | 25 |
1 files changed, 8 insertions, 17 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/rewindable_input.rb b/actionpack/lib/action_dispatch/middleware/rewindable_input.rb index 725414efc4..c818f28cce 100644 --- a/actionpack/lib/action_dispatch/middleware/rewindable_input.rb +++ b/actionpack/lib/action_dispatch/middleware/rewindable_input.rb @@ -1,27 +1,18 @@ module ActionDispatch class RewindableInput - class RewindableIO < ActiveSupport::BasicObject - def initialize(io) - @io = io - @rewindable = io.is_a?(::StringIO) - end - - def method_missing(method, *args, &block) - unless @rewindable - @io = ::StringIO.new(@io.read) - @rewindable = true - end - - @io.__send__(method, *args, &block) - end - end - def initialize(app) @app = app end def call(env) - env['rack.input'] = RewindableIO.new(env['rack.input']) + begin + env['rack.input'].rewind + rescue NoMethodError, Errno::ESPIPE + # Handles exceptions raised by input streams that cannot be rewound + # such as when using plain CGI under Apache + env['rack.input'] = StringIO.new(env['rack.input'].read) + end + @app.call(env) end end |