未验证 提交 ca21bd1b 编写于 作者: R Rafael França 提交者: GitHub

Merge pull request #35706 from jhawthorn/revert_35549_from_5_2_stable

Revert 5-2-stable backport of #35549 
......@@ -82,7 +82,6 @@ def each(&block)
SET_COOKIE = "Set-Cookie".freeze
LOCATION = "Location".freeze
NO_CONTENT_CODES = [100, 101, 102, 204, 205, 304]
CONTENT_TYPE_PARSER = /\A(?<type>[^;\s]+)?(?:.*;\s*charset=(?<quote>"?)(?<charset>[^;\s]+)\k<quote>)?/ # :nodoc:
cattr_accessor :default_charset, default: "utf-8"
cattr_accessor :default_headers
......@@ -410,8 +409,10 @@ def cookies
NullContentTypeHeader = ContentTypeHeader.new nil, nil
def parse_content_type(content_type)
if content_type && match = CONTENT_TYPE_PARSER.match(content_type)
ContentTypeHeader.new(match[:type], match[:charset])
if content_type
type, charset = content_type.split(/;\s*charset=/)
type = nil if type && type.empty?
ContentTypeHeader.new(type, charset)
else
NullContentTypeHeader
end
......
......@@ -539,38 +539,4 @@ class ResponseIntegrationTest < ActionDispatch::IntegrationTest
assert_equal('"202cb962ac59075b964b07152d234b70"', @response.headers["ETag"])
assert_equal('"202cb962ac59075b964b07152d234b70"', @response.etag)
end
test "response Content-Type with optional parameters" do
@app = lambda { |env|
[
200,
{ "Content-Type" => "text/csv; charset=utf-16; header=present" },
["Hello"]
]
}
get "/"
assert_response :success
assert_equal("text/csv; charset=utf-16; header=present", @response.headers["Content-Type"])
assert_equal("text/csv", @response.content_type)
assert_equal("utf-16", @response.charset)
end
test "response Content-Type with quoted-string" do
@app = lambda { |env|
[
200,
{ "Content-Type" => 'text/csv; header=present; charset="utf-16"' },
["Hello"]
]
}
get "/"
assert_response :success
assert_equal('text/csv; header=present; charset="utf-16"', @response.headers["Content-Type"])
assert_equal("text/csv", @response.content_type)
assert_equal("utf-16", @response.charset)
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册