Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Net::HTTPHeader#content_type
() -> (nil | ::String)
content_type
lib/net/http/header.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/lib/net/http/header.rb, line 746
def content_type
main = main_type()
return nil unless main
sub = sub_type()
if sub
"#{main}/#{sub}"
else
main
end
end
Returns 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.content_type # => "application/json"
See also
#content_type=
#content_range
#content_length=
#delete
also in
4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0