aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/lib/action_controller/rack_ext/multipart.rb4
-rw-r--r--actionpack/lib/action_controller/rewindable_input.rb30
2 files changed, 9 insertions, 25 deletions
diff --git a/actionpack/lib/action_controller/rack_ext/multipart.rb b/actionpack/lib/action_controller/rack_ext/multipart.rb
index 3d6f1f9256..3b142307e9 100644
--- a/actionpack/lib/action_controller/rack_ext/multipart.rb
+++ b/actionpack/lib/action_controller/rack_ext/multipart.rb
@@ -6,8 +6,8 @@ module Rack
result = parse_multipart_without_rewind(env)
begin
- env['rack.input'].rewind
- rescue NoMethodError, Errno::ESPIPE
+ env['rack.input'].rewind if env['rack.input'].respond_to?(:rewind)
+ rescue Errno::ESPIPE
# Handles exceptions raised by input streams that cannot be rewound
# such as when using plain CGI under Apache
end
diff --git a/actionpack/lib/action_controller/rewindable_input.rb b/actionpack/lib/action_controller/rewindable_input.rb
index 058453ea68..36f655c51e 100644
--- a/actionpack/lib/action_controller/rewindable_input.rb
+++ b/actionpack/lib/action_controller/rewindable_input.rb
@@ -3,33 +3,17 @@ module ActionController
class RewindableIO < ActiveSupport::BasicObject
def initialize(io)
@io = io
- end
-
- def read(*args)
- read_original_io
- @io.read(*args)
- end
-
- def rewind
- read_original_io
- @io.rewind
- end
-
- def string
- @string
+ @rewindable = io.is_a?(StringIO)
end
def method_missing(method, *args, &block)
- @io.send(method, *args, &block)
- end
-
- private
- def read_original_io
- unless @string
- @string = @io.read
- @io = StringIO.new(@string)
- end
+ unless @rewindable
+ @io = StringIO.new(@io.read)
+ @rewindable = true
end
+
+ @io.__send__(method, *args, &block)
+ end
end
def initialize(app)