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 201 def initialize(header_value) 202 @header_value = header_value 203 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 219 def charset 220 return @charset if defined?(@charset) 221 222 m = @header_value.to_s[CHARSET_RE, 1] 223 m && @charset = m.strip.delete('"') 224 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 208 def mime_type 209 return @mime_type if defined?(@mime_type) 210 211 m = @header_value.to_s[MIME_TYPE_RE, 1] 212 m && @mime_type = m.strip.downcase 213 end