Class: Protocol::HTTP::Header::Multiple

Inherits:
Array
  • Object
show all
Defined in:
lib/protocol/http/header/multiple.rb

Overview

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.

Direct Known Subclasses

Cookie

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Multiple

Initializes the multiple header with the given value. As the header key-value pair can only contain one value, the value given here is added to the internal array, and subsequent values can be added using the ‘<<` operator.



16
17
18
19
20
# File 'lib/protocol/http/header/multiple.rb', line 16

def initialize(value)
  super()
  
  self << value
end

Class Method Details

.trailer?Boolean

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



32
33
34
# File 'lib/protocol/http/header/multiple.rb', line 32

def self.trailer?
  false
end

Instance Method Details

#to_sObject

Serializes the stored values into a newline-separated string.



25
26
27
# File 'lib/protocol/http/header/multiple.rb', line 25

def to_s
  join("\n")
end