Represents an HTTP Accept header according to the HTTP 1.1 specification, and provides several convenience methods for determining acceptable media types.
Returns an array of media types from this header that match the given
media_type, ordered by precedence.
# File lib/rack/accept/media_type.rb, line 25 def matches(media_type) type, subtype, params = parse_media_type(media_type) values.select {|v| if v == media_type || v == '*/*' true else t, s, p = parse_media_type(v) t == type && (s == '*' || s == subtype) && (p == '' || params_match?(params, p)) end }.sort_by {|v| # Most specific gets precedence. v.length }.reverse end
The name of this header.
# File lib/rack/accept/media_type.rb, line 11 def name 'Accept' end
Determines the quality factor (qvalue) of the given
media_type.
# File lib/rack/accept/media_type.rb, line 16 def qvalue(media_type) return 1 if @qvalues.empty? m = matches(media_type) return 0 if m.empty? normalize_qvalue(@qvalues[m.first]) end
# File lib/rack/accept/media_type.rb, line 42 def initialize(header) # Strip accept-extension for now. We may want to do something with this # later if people actually start to use it. header = header.to_s.split(/,\s*/).map {|part| part.sub(/(;\s*q\s*=\s*[\d.]+).*$/, '\1') }.join(', ') super(header) end