aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2009-01-13 16:09:51 -0600
committerJoshua Peek <josh@joshpeek.com>2009-01-13 16:09:51 -0600
commit1adc1496f9152c893e1f08abcb1e5e7272829899 (patch)
tree85affcfeea0fd298b474e90e7e9870fcd2e60f77 /actionpack/lib
parent5a43908c7414996354ca427354d98d789e0210e7 (diff)
downloadrails-1adc1496f9152c893e1f08abcb1e5e7272829899.tar.gz
rails-1adc1496f9152c893e1f08abcb1e5e7272829899.tar.bz2
rails-1adc1496f9152c893e1f08abcb1e5e7272829899.zip
Add RewindableInput wrapper to fix issues with middleware that impolitely eat up non-rewindable input
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_controller.rb13
-rw-r--r--actionpack/lib/action_controller/middlewares.rb1
-rw-r--r--actionpack/lib/action_controller/rewindable_input.rb40
3 files changed, 48 insertions, 6 deletions
diff --git a/actionpack/lib/action_controller.rb b/actionpack/lib/action_controller.rb
index 8c022e5625..0d81b9c346 100644
--- a/actionpack/lib/action_controller.rb
+++ b/actionpack/lib/action_controller.rb
@@ -59,16 +59,14 @@ module ActionController
autoload :MiddlewareStack, 'action_controller/middleware_stack'
autoload :MimeResponds, 'action_controller/mime_responds'
autoload :PolymorphicRoutes, 'action_controller/polymorphic_routes'
- autoload :Request, 'action_controller/request'
- autoload :RequestParser, 'action_controller/request_parser'
- autoload :UrlEncodedPairParser, 'action_controller/url_encoded_pair_parser'
- autoload :UploadedStringIO, 'action_controller/uploaded_file'
- autoload :UploadedTempfile, 'action_controller/uploaded_file'
autoload :RecordIdentifier, 'action_controller/record_identifier'
- autoload :Response, 'action_controller/response'
+ autoload :Request, 'action_controller/request'
autoload :RequestForgeryProtection, 'action_controller/request_forgery_protection'
+ autoload :RequestParser, 'action_controller/request_parser'
autoload :Rescue, 'action_controller/rescue'
autoload :Resources, 'action_controller/resources'
+ autoload :Response, 'action_controller/response'
+ autoload :RewindableInput, 'action_controller/rewindable_input'
autoload :Routing, 'action_controller/routing'
autoload :SessionManagement, 'action_controller/session_management'
autoload :StatusCodes, 'action_controller/status_codes'
@@ -76,6 +74,9 @@ module ActionController
autoload :TestCase, 'action_controller/test_case'
autoload :TestProcess, 'action_controller/test_process'
autoload :Translation, 'action_controller/translation'
+ autoload :UploadedStringIO, 'action_controller/uploaded_file'
+ autoload :UploadedTempfile, 'action_controller/uploaded_file'
+ autoload :UrlEncodedPairParser, 'action_controller/url_encoded_pair_parser'
autoload :UrlRewriter, 'action_controller/url_rewriter'
autoload :UrlWriter, 'action_controller/url_rewriter'
autoload :VerbPiggybacking, 'action_controller/verb_piggybacking'
diff --git a/actionpack/lib/action_controller/middlewares.rb b/actionpack/lib/action_controller/middlewares.rb
index 793739723f..914750bc0c 100644
--- a/actionpack/lib/action_controller/middlewares.rb
+++ b/actionpack/lib/action_controller/middlewares.rb
@@ -18,4 +18,5 @@ use "ActiveRecord::QueryCache", :if => lambda { defined?(ActiveRecord) }
)
end
+use ActionController::RewindableInput
use ActionController::VerbPiggybacking
diff --git a/actionpack/lib/action_controller/rewindable_input.rb b/actionpack/lib/action_controller/rewindable_input.rb
new file mode 100644
index 0000000000..296d8aed22
--- /dev/null
+++ b/actionpack/lib/action_controller/rewindable_input.rb
@@ -0,0 +1,40 @@
+module ActionController
+ class RewindableInput
+ 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 method_missing(method, *args, &block)
+ @io.send(method, *args, &block)
+ end
+
+ private
+ def read_original_io
+ unless @str
+ @str = @io.read
+ @io = StringIO.new(@str)
+ end
+ 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