Feature #16773 » patch3.diff
| lib/net/http/header.rb | ||
|---|---|---|
|
# Returns a content type string such as "text".
|
||
|
# This method returns nil if Content-Type: header field does not exist.
|
||
|
def main_type
|
||
|
return nil unless @header['content-type']
|
||
|
self['Content-Type'].split(';').first.to_s.split('/')[0].to_s.strip
|
||
|
values = @header['content-type']
|
||
|
return nil unless values
|
||
|
values.first.split(';').first.to_s.split('/')[0].to_s.strip
|
||
|
end
|
||
|
# Returns a content type string such as "html".
|
||
|
# This method returns nil if Content-Type: header field does not exist
|
||
|
# or sub-type is not given (e.g. "Content-Type: text").
|
||
|
def sub_type
|
||
|
return nil unless @header['content-type']
|
||
|
_, sub = *self['Content-Type'].split(';').first.to_s.split('/')
|
||
|
values = @header['content-type']
|
||
|
return nil unless values
|
||
|
_, sub = *values.first.split(';').first.to_s.split('/')
|
||
|
return nil unless sub
|
||
|
sub.strip
|
||
|
end
|
||
- « Previous
- 1
- 2
- 3
- Next »