Helper class which decodes the HTTP “content-type” header.
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 204 def initialize(header_value) 205 @header_value = header_value 206 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 222 def charset 223 return @charset if defined?(@charset) 224 225 m = @header_value.to_s[CHARSET_RE, 1] 226 m && @charset = m.strip.delete('"') 227 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 211 def mime_type 212 return @mime_type if defined?(@mime_type) 213 214 m = @header_value.to_s[MIME_TYPE_RE, 1] 215 m && @mime_type = m.strip.downcase 216 end