Merged updates from trunk into stable branch
[feedcatcher.git] / vendor / rails / actionpack / lib / action_controller / rewindable_input.rb
diff --git a/vendor/rails/actionpack/lib/action_controller/rewindable_input.rb b/vendor/rails/actionpack/lib/action_controller/rewindable_input.rb
new file mode 100644 (file)
index 0000000..cedfb7f
--- /dev/null
@@ -0,0 +1,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