class Split
Represents headers that can contain multiple distinct values separated by commas.
This isn't a specific header class is a utility for handling headers with comma-separated values, such as accept
, cache-control
, and other similar headers. The values are split and stored as an array internally, and serialized back to a comma-separated string when needed.
Definitions
COMMA = /\s*,\s*/
Regular expression used to split values on commas, with optional surrounding whitespace.
def initialize(value = nil)
Initializes a Split
header with the given value. If the value is provided, it is split into distinct entries and stored as an array.
Signature
-
parameter
value
String | Nil
the raw header value containing multiple entries separated by commas, or
nil
for an empty header.
Implementation
def initialize(value = nil)
if value
super(value.split(COMMA))
else
super()
end
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
the value or values to add, separated by commas.
Implementation
def << value
self.concat(value.split(COMMA))
end
def to_s
Serializes the stored values into a comma-separated string.
Signature
-
returns
String
the serialized representation of the header values.
Implementation
def to_s
join(",")
end
def self.trailer?
Whether this header is acceptable in HTTP trailers. This is a base class for comma-separated headers, default is to disallow in trailers.
Signature
-
returns
Boolean
false
, as most comma-separated headers should not appear in trailers by default.
Implementation
def self.trailer?
false
end