このマニュアルは既にメンテナンスが終了したバージョンの Ruby を対象としています。 最新版のマニュアルへ

Ruby 2.5.0 リファレンスマニュアル

instance method Net::HTTPHeader#sub_type

sub_type -> String|nil[permalink][rdoc]

"text/html" における "html" のようなサブタイプを表す文字列を返します。

Content-Type: ヘッダフィールドが存在しない場合には nil を返します。


require 'net/http'

uri = URI.parse('http://www.example.com/index.html')
res = Net::HTTP.get_response(uri)
res.sub_type # => "html"