mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Always buffer rack.input if it is not rewindable
Signed-off-by: Joshua Peek <josh@joshpeek.com>
This commit is contained in:
committed by
Joshua Peek
parent
878aec9d95
commit
35c5727ace
@@ -1,27 +1,18 @@
|
||||
module ActionController
|
||||
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
|
||||
|
||||
@@ -94,7 +94,7 @@ class DispatcherTest < Test::Unit::TestCase
|
||||
def dispatch(cache_classes = true)
|
||||
ActionController::Routing::RouteSet.any_instance.stubs(:call).returns([200, {}, 'response'])
|
||||
Dispatcher.define_dispatcher_callbacks(cache_classes)
|
||||
Dispatcher.new.call({})
|
||||
Dispatcher.new.call({'rack.input' => StringIO.new('')})
|
||||
end
|
||||
|
||||
def assert_subclasses(howmany, klass, message = klass.subclasses.inspect)
|
||||
|
||||
@@ -207,6 +207,7 @@ class MultipartParamsParsingTest < ActionController::IntegrationTest
|
||||
|
||||
def call(env)
|
||||
env['rack.input'].read
|
||||
env['rack.input'].rewind
|
||||
@app.call(env)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -151,6 +151,7 @@ class UrlEncodedParamsParsingTest < ActionController::IntegrationTest
|
||||
|
||||
def call(env)
|
||||
env['rack.input'].read
|
||||
env['rack.input'].rewind
|
||||
@app.call(env)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user