class Protocol::HTTP::Header::Accept
The ‘accept-content-type` header represents a list of content-types that the client can accept.
def << (value)
The input string is split into distinct entries and appended to the array.
Adds one or more comma-separated values to the header.
def << (value) self.concat(value.scan(SEPARATOR).map(&:strip)) end
def initialize(value = nil)
Parse the `accept` header value into a list of content types.
def initialize(value = nil) if value super(value.scan(SEPARATOR).map(&:strip)) end end
def media_ranges
Parse the `accept` header.
def media_ranges self.map do |value| self.parse_media_range(value) end end
def parse_media_range(value)
def parse_media_range(value) if match = value.match(MEDIA_RANGE) type = match[:type] subtype = match[:subtype] parameters = {} match[:parameters].scan(PARAMETER) do |key, value, quoted_value| if quoted_value value = QuotedString.unquote(quoted_value) end parameters[key] = value end return MediaRange.new(type, subtype, parameters) else raise ParseError, "Invalid media type: #{value.inspect}" end end
def to_s
Serializes the stored values into a comma-separated string.
def to_s join(",") end