instance method set_content_type

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

set_content_type(content_type, charset)

No documentation comment.

Parameters

content_type req
charset req
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

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