diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2009-04-20 18:31:22 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2009-04-20 18:31:40 -0700 |
commit | 685a53a360d0d8fc4a9f3b49f900621c940a71f2 (patch) | |
tree | fa6b38f75a873a21c3e380f1acbab3d019293363 /actionpack/lib/action_dispatch/middleware/rewindable_input.rb | |
parent | db05c73fb6e2294c576ef9889c70940891682c32 (diff) | |
parent | 164a94d0bc8c9124ab820506e5ad79496395c026 (diff) | |
download | rails-685a53a360d0d8fc4a9f3b49f900621c940a71f2.tar.gz rails-685a53a360d0d8fc4a9f3b49f900621c940a71f2.tar.bz2 rails-685a53a360d0d8fc4a9f3b49f900621c940a71f2.zip |
Merge branch 'master' into cherry
Conflicts:
activesupport/CHANGELOG
activesupport/lib/active_support/core_ext/class/delegating_attributes.rb
activesupport/lib/active_support/core_ext/hash/conversions.rb
activesupport/lib/active_support/core_ext/module/attribute_accessors.rb
activesupport/lib/active_support/core_ext/string/multibyte.rb
activesupport/lib/active_support/core_ext/time/calculations.rb
activesupport/lib/active_support/deprecation.rb
Diffstat (limited to 'actionpack/lib/action_dispatch/middleware/rewindable_input.rb')
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/rewindable_input.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/rewindable_input.rb b/actionpack/lib/action_dispatch/middleware/rewindable_input.rb new file mode 100644 index 0000000000..725414efc4 --- /dev/null +++ b/actionpack/lib/action_dispatch/middleware/rewindable_input.rb @@ -0,0 +1,28 @@ +module ActionDispatch + class RewindableInput + class RewindableIO < ActiveSupport::BasicObject + def initialize(io) + @io = io + @rewindable = io.is_a?(::StringIO) + end + + def method_missing(method, *args, &block) + unless @rewindable + @io = ::StringIO.new(@io.read) + @rewindable = true + end + + @io.__send__(method, *args, &block) + end + end + + def initialize(app) + @app = app + end + + def call(env) + env['rack.input'] = RewindableIO.new(env['rack.input']) + @app.call(env) + end + end +end |