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 212 def initialize(header_value) 213 @header_value = header_value 214 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 230 def charset 231 return @charset if defined?(@charset) 232 233 m = @header_value.to_s[CHARSET_RE, 1] 234 m && @charset = m.strip.delete('"') 235 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 219 def mime_type 220 return @mime_type if defined?(@mime_type) 221 222 m = @header_value.to_s[MIME_TYPE_RE, 1] 223 m && @mime_type = m.strip.downcase 224 end