diff --git a/lib/net/http/header.rb b/lib/net/http/header.rb index 6106e79..0a02514 100644 --- a/lib/net/http/header.rb +++ b/lib/net/http/header.rb @@ -740,7 +740,11 @@ def content_type # def main_type return nil unless @header['content-type'] - self['Content-Type'].split(';').first.to_s.split('/')[0].to_s.strip + value = self['Content-Type'] + offset = (value.index(';') || value.length).clamp(0, value.index('/') || value.length) + type = value[0, offset] + type.strip! + type end # Returns the trailing ('subtype') part of the @@ -755,9 +759,14 @@ def main_type # def sub_type return nil unless @header['content-type'] - _, sub = *self['Content-Type'].split(';').first.to_s.split('/') - return nil unless sub - sub.strip + value = self['Content-Type'] + end_offset = value.index(";") || value.length + return unless start_offset = value.index("/") + return if start_offset > end_offset + start_offset += 1 + sub = value[start_offset, end_offset - start_offset] + sub.strip! + sub end # Returns the trailing ('parameters') part of the value of field 'Content-Type',