instance method
set_content_type
Ruby on Rails edge
Since v5.0.7.2 Private — implementation detail, not part of the public APISignature
set_content_type(content_type, charset)
No documentation comment.
Parameters
-
content_typereq -
charsetreq
Source
# File actionpack/lib/action_dispatch/http/response.rb, line 534
def set_content_type(content_type, charset)
type = content_type || ""
if charset
charset = charset.to_s.downcase
type = "#{type}; charset=#{charset}"
else
charset = nil
end
set_header CONTENT_TYPE, type
# We serialized the parts ourselves, so prime the parsed-header memo
# instead of letting the reader regexp-parse our own output back apart.
# Parts the parser could read differently, or that aren't in the encoding
# of the header it would read them from, go through the parser.
mime_type = content_type.presence
unless mime_type&.match?(AMBIGUOUS_CONTENT_TYPE_PART) || charset&.match?(AMBIGUOUS_CONTENT_TYPE_PART) || charset == "" ||
(mime_type && mime_type.encoding != type.encoding) || (charset && charset.encoding != type.encoding)
@parsed_content_type_raw = -type
@parsed_content_type = ContentTypeHeader.new(mime_type, charset)
end
end
Defined in actionpack/lib/action_dispatch/http/response.rb line 534
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActionDispatch::Response