Skip to content
This repository
tree: 9714a9b001
Fetching contributors…

Cannot retrieve contributors at this time

file 28 lines (24 sloc) 0.586 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
module ActionController
  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
Something went wrong with that request. Please try again.