class HTTPX::ContentType

  1. lib/httpx/response.rb
Superclass: Object

Helper class which decodes the HTTP “content-type” header.

Methods

Public Class

  1. new

Public Instance

  1. charset
  2. mime_type

Constants

CHARSET_RE = /;\s*charset=([^;]+)/i.freeze  
MIME_TYPE_RE = %r{^([^/]+/[^;]+)(?:$|;)}.freeze  

Public Class methods

new(header_value)
[show source]
    # File lib/httpx/response.rb
212 def initialize(header_value)
213   @header_value = header_value
214   @mime_type = @charset = nil
215   @initialized = false
216 end

Public Instance methods

charset()

returns the charset declared in the header.

ContentType.new("application/json; charset=utf-8").charset #=> "utf-8"
ContentType.new("text/plain").charset #=> nil
[show source]
    # File lib/httpx/response.rb
233 def charset
234   return @charset if @initialized
235 
236   load
237 
238   @charset
239 end
mime_type()

returns the mime type declared in the header.

ContentType.new("application/json; charset=utf-8").mime_type #=> "application/json"
[show source]
    # File lib/httpx/response.rb
221 def mime_type
222   return @mime_type if @initialized
223 
224   load
225 
226   @mime_type
227 end