Protocol::HTTPSourceProtocolHTTPHeaderMultiple

class Multiple

Represents headers that can contain multiple distinct values separated by newline characters.

This isn't a specific header but is used as a base for headers that store multiple values, such as cookies. The values are split and stored as an array internally, and serialized back to a newline-separated string when needed.

Definitions

def self.parse(value)

Parses a raw header value.

Multiple headers receive each value as a separate header entry, so this method takes a single string value and creates a new instance containing it.

Signature

parameter value String

a single raw header value.

returns Multiple

a new instance containing the parsed value.

Implementation

def self.parse(value)
	self.new([value])
end

def self.coerce(value)

Coerces a value into a parsed header object.

This method is used by the Headers class when setting values via []= to convert application values into the appropriate policy type.

Signature

parameter value String | Array

the value to coerce.

returns Multiple

a parsed header object.

Implementation

def self.coerce(value)
	case value
	when Array
		self.new(value.map(&:to_s))
	else
		self.parse(value.to_s)
	end
end

def initialize(value = nil)

Initializes the multiple header with the given values.

Signature

parameter value Array | Nil

an array of header values, or nil for an empty header.

Implementation

def initialize(value = nil)
	super()
	
	if value
		self.concat(value)
	end
end

def to_s

Converts the parsed header value into a raw header value.

Multiple headers are transmitted as separate header entries, so this serializes to a newline-separated string for storage.

Signature

returns String

a raw header value (newline-separated string).

Implementation

def to_s
	join("\n")
end

def self.trailer?

Whether this header is acceptable in HTTP trailers. This is a base class for headers with multiple values, default is to disallow in trailers.

Signature

returns Boolean

false, as most multiple-value headers should not appear in trailers by default.

Implementation

def self.trailer?
	false
end