Permalink
Browse files

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

…1767 state:resolved]
  • Loading branch information...
1 parent 515a1a3 commit 29e7a0242853a5e102b6846b87723fc26a1ffb08 @josh josh committed Jan 17, 2009
@@ -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
@@ -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)

0 comments on commit 29e7a02

Please sign in to comment.