cedfb7fd75e64c1d7ca46f6bd0d3675b511e94e2
[feedcatcher.git] / vendor / rails / actionpack / lib / action_controller / rewindable_input.rb
1 module ActionController
2 class RewindableInput
3 class RewindableIO < ActiveSupport::BasicObject
4 def initialize(io)
5 @io = io
6 @rewindable = io.is_a?(::StringIO)
7 end
8
9 def method_missing(method, *args, &block)
10 unless @rewindable
11 @io = ::StringIO.new(@io.read)
12 @rewindable = true
13 end
14
15 @io.__send__(method, *args, &block)
16 end
17 end
18
19 def initialize(app)
20 @app = app
21 end
22
23 def call(env)
24 env['rack.input'] = RewindableIO.new(env['rack.input'])
25 @app.call(env)
26 end
27 end
28 end