aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2009-01-17 11:12:18 -0600
committerJoshua Peek <josh@joshpeek.com>2009-01-17 11:12:18 -0600
commit29e7a0242853a5e102b6846b87723fc26a1ffb08 (patch)
tree6ad8a437d4422ce0247a61ebb03457610fdfded7 /actionpack
parent515a1a332808eb7c2f9c006fc1903e1e8555b7fa (diff)
downloadrails-29e7a0242853a5e102b6846b87723fc26a1ffb08.tar.gz
rails-29e7a0242853a5e102b6846b87723fc26a1ffb08.tar.bz2
rails-29e7a0242853a5e102b6846b87723fc26a1ffb08.zip
Ensure any method sent to RewindableIO reads the original IO object [#1767 state:resolved]
Diffstat (limited to 'actionpack')
-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)