Class: HTTPX::ContentType
- Inherits:
-
Object
- Object
- HTTPX::ContentType
- Defined in:
- lib/httpx/response.rb
Overview
Helper class which decodes the HTTP “content-type” header.
Constant Summary collapse
- MIME_TYPE_RE =
%r{^([^/]+/[^;]+)(?:$|;)}.freeze
- CHARSET_RE =
/;\s*charset=([^;]+)/i.freeze
Instance Method Summary collapse
-
#charset ⇒ Object
returns the charset declared in the header.
-
#initialize(header_value) ⇒ ContentType
constructor
A new instance of ContentType.
-
#mime_type ⇒ Object
returns the mime type declared in the header.
Constructor Details
#initialize(header_value) ⇒ ContentType
Returns a new instance of ContentType.
212 213 214 215 216 |
# File 'lib/httpx/response.rb', line 212 def initialize(header_value) @header_value = header_value @mime_type = @charset = nil @initialized = false end |
Instance Method Details
#charset ⇒ Object
returns the charset declared in the header.
ContentType.new("application/json; charset=utf-8").charset #=> "utf-8"
ContentType.new("text/plain").charset #=> nil
233 234 235 236 237 238 239 |
# File 'lib/httpx/response.rb', line 233 def charset return @charset if @initialized load @charset end |
#mime_type ⇒ Object
returns the mime type declared in the header.
ContentType.new("application/json; charset=utf-8").mime_type #=> "application/json"
221 222 223 224 225 226 227 |
# File 'lib/httpx/response.rb', line 221 def mime_type return @mime_type if @initialized load @mime_type end |