Project

General

Profile

Feature #16773 ยป patch3.diff

timcraft (Tim Craft), 04/10/2020 11:35 AM

View differences:

lib/net/http/header.rb
362 362
  # Returns a content type string such as "text".
363 363
  # This method returns nil if Content-Type: header field does not exist.
364 364
  def main_type
365
    return nil unless @header['content-type']
366
    self['Content-Type'].split(';').first.to_s.split('/')[0].to_s.strip
365
    values = @header['content-type']
366
    return nil unless values
367
    values.first.split(';').first.to_s.split('/')[0].to_s.strip
367 368
  end
368 369

  
369 370
  # Returns a content type string such as "html".
370 371
  # This method returns nil if Content-Type: header field does not exist
371 372
  # or sub-type is not given (e.g. "Content-Type: text").
372 373
  def sub_type
373
    return nil unless @header['content-type']
374
    _, sub = *self['Content-Type'].split(';').first.to_s.split('/')
374
    values = @header['content-type']
375
    return nil unless values
376
    _, sub = *values.first.split(';').first.to_s.split('/')
375 377
    return nil unless sub
376 378
    sub.strip
377 379
  end