module HTTP::Accept::MediaTypes

Parse and process the HTTP Accept: header.

Constants

MIME_TYPE

According to tools.ietf.org/html/rfc7231#section-5.3.2

MediaRange

A single entry in the Accept: header, which includes a mime type and associated parameters.

PARAMETER

Public Class Methods

parse(scanner, normalize_whitespace = true) { |self| ... } click to toggle source
# File lib/http/accept/media_types.rb, line 96
def self.parse(scanner, normalize_whitespace = true)
        return to_enum(:parse, scanner, normalize_whitespace) unless block_given?
        
        while scanner.scan(MIME_TYPE)
                type = scanner[:type]
                subtype = scanner[:subtype]
                
                parameters = parse_parameters(scanner, normalize_whitespace)
                
                yield self.new(type, subtype, parameters)
                
                # Are there more?
                break unless scanner.scan(/\s*,\s*/)
        end
        
        raise ParseError.new("Could not parse entire string!") unless scanner.eos?
end