Skip to content

Commit

Permalink
Ensure any method sent to RewindableIO reads the original IO object [#…
Browse files Browse the repository at this point in the history
…1767 state:resolved]
  • Loading branch information
josh committed Jan 17, 2009
1 parent 515a1a3 commit 29e7a02
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 25 deletions.
4 changes: 2 additions & 2 deletions actionpack/lib/action_controller/rack_ext/multipart.rb
Expand Up @@ -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
Expand Down
30 changes: 7 additions & 23 deletions actionpack/lib/action_controller/rewindable_input.rb
Expand Up @@ -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)
Expand Down

0 comments on commit 29e7a02

Please sign in to comment.