Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"head" renders valid JSON if response type is "application/json" #8124

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion actionpack/lib/action_controller/metal/head.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ def head(status, options = {})


if include_content?(self.status) if include_content?(self.status)
self.content_type = content_type || (Mime[formats.first] if formats) self.content_type = content_type || (Mime[formats.first] if formats)
self.response_body = " " if self.content_type == "application/json"
self.response_body = "{}"
else
self.response_body = " "
end
else else
headers.delete('Content-Type') headers.delete('Content-Type')
headers.delete('Content-Length') headers.delete('Content-Length')
Expand Down
2 changes: 1 addition & 1 deletion actionpack/test/controller/render_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1219,7 +1219,7 @@ def test_head_created


def test_head_created_with_application_json_content_type def test_head_created_with_application_json_content_type
post :head_created_with_application_json_content_type post :head_created_with_application_json_content_type
assert_blank @response.body assert_nothing_raised { JSON.parse(@response.body) }
assert_equal "application/json", @response.content_type assert_equal "application/json", @response.content_type
assert_response :created assert_response :created
end end
Expand Down