instance method
Net::HTTPHeader#main_type
() -> (nil | ::String)
main_type
lib/net/http/header.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.0.0/lib/net/http/header.rb, line 727
def main_type
return nil unless @header['content-type']
self['Content-Type'].split(';').first.to_s.split('/')[0].to_s.strip
end
Returns the leading (‘type’) part of the media type from the value of field 'Content-Type', or nil if no such field exists; see Content-Type response header:
Example
res = Net::HTTP.get_response(hostname, '/todos/1') res['content-type'] # => "application/json; charset=utf-8" res.main_type # => "application"