Method: Gem::Net::HTTPHeader#sub_type

Defined in:
lib/rubygems/net-http/lib/net/http/header.rb

#sub_typeObject

Returns the trailing (‘subtype’) part of the media type from the value of field 'Content-Type', or nil if no such field exists; see Content-Type response header:

res = Gem::Net::HTTP.get_response(hostname, '/todos/1')
res['content-type'] # => "application/json; charset=utf-8"
res.sub_type        # => "json"


738
739
740
741
742
743
# File 'lib/rubygems/net-http/lib/net/http/header.rb', line 738

def sub_type
  return nil unless @header['content-type']
  _, sub = *self['Content-Type'].split(';').first.to_s.split('/')
  return nil unless sub
  sub.strip
end