instance method
parsed_content_type_header
Ruby on Rails edge
Since v5.0.7.2 Private — implementation detail, not part of the public APISignature
parsed_content_type_header()
Small internal convenience method to get the parsed version of the current content type header. The result is memoized per raw header value, since the header is read several times per request (content negotiation, charset, committing the response) and parsing allocates a MatchData and its captures each time. A missing header is not memoized: it parses to a shared null object without allocating.
Source
# File actionpack/lib/action_dispatch/http/response.rb, line 512
def parsed_content_type_header
raw = get_header(CONTENT_TYPE)
return NullContentTypeHeader unless raw
# The memo key is a frozen copy, so changing the header in place misses it.
# It is stored only once parsing succeeds, and the encoding is compared
# because == ignores it for ASCII-only strings.
memoized_raw = @parsed_content_type_raw
if raw == memoized_raw && raw.encoding == memoized_raw.encoding
@parsed_content_type
else
@parsed_content_type = parse_content_type(raw)
@parsed_content_type_raw = -raw
@parsed_content_type
end
end
Defined in actionpack/lib/action_dispatch/http/response.rb line 512
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActionDispatch::Response