File: multiple.rb

package info (click to toggle)
ruby-protocol-http 0.55.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 840 kB
  • sloc: ruby: 6,904; makefile: 4
file content (38 lines) | stat: -rw-r--r-- 1,401 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2019-2025, by Samuel Williams.

module Protocol
	module HTTP
		module Header
			# 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.
			class Multiple < Array
				# 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.
				#
				# @parameter value [String] the raw header value.
				def initialize(value)
					super()
					
					self << value
				end
				
				# Serializes the stored values into a newline-separated string.
				#
				# @returns [String] the serialized representation of the header values.
				def to_s
					join("\n")
				end
				
				# Whether this header is acceptable in HTTP trailers.
				# This is a base class for headers with multiple values, default is to disallow in trailers.
				# @returns [Boolean] `false`, as most multiple-value headers should not appear in trailers by default.
				def self.trailer?
					false
				end
			end
		end
	end
end