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 213 def initialize(header_value) 214 @header_value = header_value 215 @mime_type = @charset = nil 216 @initialized = false 217 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 234 def charset 235 return @charset if @initialized 236 237 load 238 239 @charset 240 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 222 def mime_type 223 return @mime_type if @initialized 224 225 load 226 227 @mime_type 228 end