Class: HTTPX::ContentType

Inherits:
Object
  • Object
show all
Defined in:
lib/httpx/response.rb,
sig/response.rbs

Overview

Helper class which decodes the HTTP "content-type" header.

Constant Summary collapse

SPLIT_PATTERN =

Returns:

  • (Regexp)
/[;,]/.freeze

Instance Method Summary collapse

Instance Method Details

#charset ⇒ String?

returns the charset declared in the header.

ContentType.new("application/json; charset=utf-8").charset #=> "utf-8"
ContentType.new("text/plain").charset #=> nil

Returns:

  • (String, nil)


240
241
242
243
244
245
246
# File 'lib/httpx/response.rb', line 240

def charset
  return @charset if @initialized

  load

  @charset
end

#mime_type ⇒ String?

returns the mime type declared in the header.

ContentType.new("application/json; charset=utf-8").mime_type #=> "application/json"

Returns:

  • (String, nil)


228
229
230
231
232
233
234
# File 'lib/httpx/response.rb', line 228

def mime_type
  return @mime_type if @initialized

  load

  @mime_type
end