Protocol::HTTPSourceProtocolHTTPHeaderAccept

class Accept

The accept-content-type header represents a list of content-types that the client can accept.

Nested

Definitions

SEPARATOR

Regular expression used to split values on commas, with optional surrounding whitespace, taking into account quoted strings.

Implementation

SEPARATOR = /
	(?:            # Start non-capturing group
		"[^"\\]*"    # Match quoted strings (no escaping of quotes within)
		|            # OR
		[^,"]+       # Match non-quoted strings until a comma or quote
	)+
	(?=,|\z)       # Match until a comma or end of string
/x

def self.parse(value)

Parses a raw header value.

Signature

parameter value String

a raw header value containing comma-separated media types.

returns Accept

a new instance containing the parsed media types.

Implementation

def self.parse(value)
	self.new(value.scan(SEPARATOR).map(&:strip))
end

def <<(value)

Adds one or more comma-separated values to the header.

The input string is split into distinct entries and appended to the array.

Signature

parameter value String

a raw header value containing one or more media types separated by commas.

Implementation

def << value
	self.concat(value.scan(SEPARATOR).map(&:strip))
end

def to_s

Converts the parsed header value into a raw header value.

Signature

returns String

a raw header value (comma-separated string).

Implementation

def to_s
	join(",")
end

def self.trailer?

Whether this header is acceptable in HTTP trailers.

Signature

returns Boolean

false, as Accept headers are used for response content negotiation.

Implementation

def self.trailer?
	false
end

def media_ranges

Parse the accept header.

Signature

returns Array(Charset)

the list of content types and their associated parameters.

Implementation

def media_ranges
	self.map do |value|
		self.parse_media_range(value)
	end
end