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 221 def initialize(header_value) 222 @header_value = header_value 223 @mime_type = @charset = nil 224 @initialized = false 225 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 242 def charset 243 return @charset if @initialized 244 245 load 246 247 @charset 248 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 230 def mime_type 231 return @mime_type if @initialized 232 233 load 234 235 @mime_type 236 end