instance method parsed_content_type_header

Ruby on Rails edge

Since v5.0.7.2 Private — implementation detail, not part of the public API

Available in: v5.0.7.2 v5.1.7 v5.2.8.1 v6.0.6.1 v6.1.7.10 v7.0.10 v7.1.6 v7.2.4 v8.0.5.1 v8.1.4 edge

Signature

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

Type at least 2 characters to search.

Use the arrow keys to navigate results, Enter to open one, Escape to close.

Keyboard shortcuts

/
Focus search
⌘K / Ctrl-K
Command palette
?
This help
Esc
Close