Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Ensure any method sent to RewindableIO reads the original IO object [#…

…1767 state:resolved]
  • Loading branch information...
commit 29e7a0242853a5e102b6846b87723fc26a1ffb08 1 parent 515a1a3
Joshua Peek josh authored
4 actionpack/lib/action_controller/rack_ext/multipart.rb
View
@@ -6,8 +6,8 @@ def parse_multipart_with_rewind(env)
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
30 actionpack/lib/action_controller/rewindable_input.rb
View
@@ -3,33 +3,17 @@ class RewindableInput
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)
Please sign in to comment.
Something went wrong with that request. Please try again.