aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG2
-rwxr-xr-xactionpack/lib/action_controller/request.rb4
-rwxr-xr-xactionpack/test/controller/cgi_test.rb17
3 files changed, 22 insertions, 1 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index f6a40f62d1..1aa2d5b521 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Rewind request body after reading it, if possible. #8438 [s450r1]
+
* Resource namespaces are inherited by their has_many subresources. #8280 [marclove, ggarside]
* Fix filtered parameter logging with nil parameter values. #8422 [choonkeat]
diff --git a/actionpack/lib/action_controller/request.rb b/actionpack/lib/action_controller/request.rb
index 0dfc4a91d0..476f65a6dc 100755
--- a/actionpack/lib/action_controller/request.rb
+++ b/actionpack/lib/action_controller/request.rb
@@ -330,7 +330,9 @@ module ActionController
# Only multipart form parsing expects a stream.
if strategy && strategy != :multipart_form
- body = body.read(content_length)
+ data = body.read(content_length)
+ body.rewind if body.respond_to?(:rewind)
+ body = data
end
case strategy
diff --git a/actionpack/test/controller/cgi_test.rb b/actionpack/test/controller/cgi_test.rb
index 4c3fbc37c5..da3ca245e1 100755
--- a/actionpack/test/controller/cgi_test.rb
+++ b/actionpack/test/controller/cgi_test.rb
@@ -68,3 +68,20 @@ class CgiRequestParamsParsingTest < BaseCgiTest
assert_equal({"flamenco"=> "love"}, @request.request_parameters)
end
end
+
+
+class CgiRequestNeedsRewoundTest < BaseCgiTest
+ def test_body_should_be_rewound
+ data = 'foo'
+ fake_cgi = Struct.new(:env_table, :query_string, :stdinput).new(@request_hash, '', StringIO.new(data))
+ fake_cgi.env_table['CONTENT_LENGTH'] = data.length
+ fake_cgi.env_table['CONTENT_TYPE'] = 'application/x-www-form-urlencoded; charset=utf-8'
+
+ # Read the request body by parsing params.
+ request = ActionController::CgiRequest.new(fake_cgi)
+ request.request_parameters
+
+ # Should have rewound the body.
+ assert_equal 0, request.body.pos
+ end
+end