mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Remove Content-Length header from :no_content responses
This commit is contained in:
parent
48963a55c7
commit
074414883c
2 changed files with 12 additions and 4 deletions
|
@ -231,10 +231,13 @@ module ActionController # :nodoc:
|
||||||
# Don't set the Content-Length for block-based bodies as that would mean
|
# Don't set the Content-Length for block-based bodies as that would mean
|
||||||
# reading it all into memory. Not nice for, say, a 2GB streaming file.
|
# reading it all into memory. Not nice for, say, a 2GB streaming file.
|
||||||
def set_content_length!
|
def set_content_length!
|
||||||
unless body.respond_to?(:call) || (status && status.to_s[0..2] == '304')
|
if status && status.to_s[0..2] == '204'
|
||||||
self.headers["Content-Length"] ||= body.size
|
headers.delete('Content-Length')
|
||||||
|
elsif length = headers['Content-Length']
|
||||||
|
headers['Content-Length'] = length.to_s
|
||||||
|
elsif !body.respond_to?(:call) && (!status || status.to_s[0..2] != '304')
|
||||||
|
headers["Content-Length"] = body.size.to_s
|
||||||
end
|
end
|
||||||
headers["Content-Length"] = headers["Content-Length"].to_s if headers["Content-Length"]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def convert_language!
|
def convert_language!
|
||||||
|
|
|
@ -1218,6 +1218,11 @@ class RenderTest < ActionController::TestCase
|
||||||
assert_equal "404 Not Found", @response.status
|
assert_equal "404 Not Found", @response.status
|
||||||
assert_response :not_found
|
assert_response :not_found
|
||||||
|
|
||||||
|
get :head_with_symbolic_status, :status => "no_content"
|
||||||
|
assert_equal "204 No Content", @response.status
|
||||||
|
assert !@response.headers.include?('Content-Length')
|
||||||
|
assert_response :no_content
|
||||||
|
|
||||||
ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE.each do |status, code|
|
ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE.each do |status, code|
|
||||||
get :head_with_symbolic_status, :status => status.to_s
|
get :head_with_symbolic_status, :status => status.to_s
|
||||||
assert_equal code, @response.response_code
|
assert_equal code, @response.response_code
|
||||||
|
@ -1470,7 +1475,7 @@ class EtagRenderTest < ActionController::TestCase
|
||||||
def test_render_against_etag_request_should_have_no_content_length_when_match
|
def test_render_against_etag_request_should_have_no_content_length_when_match
|
||||||
@request.if_none_match = etag_for("hello david")
|
@request.if_none_match = etag_for("hello david")
|
||||||
get :render_hello_world_from_variable
|
get :render_hello_world_from_variable
|
||||||
assert !@response.headers.has_key?("Content-Length")
|
assert !@response.headers.has_key?("Content-Length"), @response.headers['Content-Length']
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_render_against_etag_request_should_200_when_no_match
|
def test_render_against_etag_request_should_200_when_no_match
|
||||||
|
|
Loading…
Reference in a new issue