Skip to content

Commit

Permalink
fixes raw_post being empty for chunked request
Browse files Browse the repository at this point in the history
  • Loading branch information
hahmed committed Dec 30, 2019
1 parent 22483b8 commit a1375fd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
13 changes: 12 additions & 1 deletion actionpack/lib/action_dispatch/http/request.rb
Expand Up @@ -321,12 +321,23 @@ def server_software
def raw_post
unless has_header? "RAW_POST_DATA"
raw_post_body = body
set_header("RAW_POST_DATA", raw_post_body.read(content_length))
set_header("RAW_POST_DATA",
if chunked?
raw_post_body.rewind if raw_post_body.respond_to?(:rewind)
raw_post_body.read
else
raw_post_body.read(content_length)
end
)
raw_post_body.rewind if raw_post_body.respond_to?(:rewind)
end
get_header "RAW_POST_DATA"
end

def chunked?
headers["Transfer-Encoding"] =~ /chunked/i
end

# The request body is an IO input stream. If the RAW_POST_DATA environment
# variable is already set, wrap it in a StringIO.
def body
Expand Down
6 changes: 6 additions & 0 deletions actionpack/test/controller/test_case_test.rb
Expand Up @@ -990,6 +990,12 @@ def test_parsed_body_with_as_option
post :render_json, body: { foo: "heyo" }.to_json, as: :json
assert_equal({ "foo" => "heyo" }, response.parsed_body)
end

def test_chunked_request
@request.headers["Transfer-Encoding"] = "chunked"
post :test_params, params: { foo: "heyo" }, xhr: true
assert_equal("foo=heyo", @request.raw_post)
end
end

class ResponseDefaultHeadersTest < ActionController::TestCase
Expand Down

0 comments on commit a1375fd

Please sign in to comment.