Use Request#raw_post instead Request#body

In order to get raw_post to be not empty after
ParamsParser#parse_formatted_parameters,
added rewinding of body stream input on parsing json params.

Closes #11345
This commit is contained in:
Paul Nikitochkin 2013-07-08 01:32:22 +03:00
parent b18a27375a
commit f6746c0245
3 changed files with 15 additions and 1 deletions

@ -1,3 +1,10 @@
* Fix `ActionDispatch::ParamsParser#parse_formatted_parameters` to rewind body input stream on
parsing json params.
Fixes #11345
*Yuri Bol*, *Paul Nikitochkin*
* Ignore spaces around delimiter in Set-Cookie header.
*Yamagishi Kazutoshi*

@ -41,7 +41,7 @@ def parse_formatted_parameters(env)
when Proc
strategy.call(request.raw_post)
when :json
data = ActiveSupport::JSON.decode(request.body)
data = ActiveSupport::JSON.decode(request.raw_post)
data = {:_json => data} unless data.is_a?(Hash)
Request::Utils.deep_munge(data).with_indifferent_access
else

@ -70,6 +70,13 @@ def teardown
end
end
test 'raw_post is not empty for JSON request' do
with_test_routing do
post '/parse', '{"posts": [{"title": "Post Title"}]}', 'CONTENT_TYPE' => 'application/json'
assert_equal '{"posts": [{"title": "Post Title"}]}', request.raw_post
end
end
private
def assert_parses(expected, actual, headers = {})
with_test_routing do