You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- `Header::*.new(value)` method expects the correct data type and does not coerce from String.
- Parsing logic was moved to `Header::*.parse(value)`.
- Coercion to header values is now handled by `Header::*.coerce(value)`.
Copy file name to clipboardExpand all lines: lib/protocol/http/body/stream.rb
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@
10
10
moduleProtocol
11
11
moduleHTTP
12
12
moduleBody
13
-
# The input stream is an IO-like object which contains the raw HTTP POST data. When applicable, its external encoding must be “ASCII-8BIT” and it must be opened in binary mode, for Ruby 1.9 compatibility. The input stream must respond to gets, each, read and rewind.
13
+
# The input stream is an IO-like object which contains the raw HTTP POST data. When applicable, its external encoding must be "ASCII-8BIT" and it must be opened in binary mode, for Ruby 1.9 compatibility. The input stream must respond to gets, each, read and rewind.
Copy file name to clipboardExpand all lines: lib/protocol/http/header/etag.rb
+18-2Lines changed: 18 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -10,9 +10,25 @@ module Header
10
10
#
11
11
# The `etag` header provides a unique identifier for a specific version of a resource, typically used for cache validation or conditional requests. It can be either a strong or weak validator as defined in RFC 9110.
12
12
classETag < String
13
-
# Replaces the current value of the `etag` header with the specified value.
13
+
# Parses a raw header value from the wire.
14
14
#
15
-
# @parameter value [String] the new value for the `etag` header.
15
+
# @parameter value [String] the raw header value.
16
+
# @returns [ETag] a new instance.
17
+
defself.parse(value)
18
+
self.new(value)
19
+
end
20
+
21
+
# Coerces a value into a parsed header object.
22
+
#
23
+
# @parameter value [String] the value to coerce.
24
+
# @returns [ETag] a parsed header object.
25
+
defself.coerce(value)
26
+
self.new(value.to_s)
27
+
end
28
+
29
+
# Replaces the current value of the `etag` header with a raw wire-format string.
30
+
#
31
+
# @parameter value [String] a raw wire-format value for the `etag` header.
Copy file name to clipboardExpand all lines: lib/protocol/http/header/multiple.rb
+35-6Lines changed: 35 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -10,18 +10,47 @@ module Header
10
10
#
11
11
# 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.
12
12
classMultiple < Array
13
-
# 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.
13
+
# Parses a raw header value from the wire.
14
14
#
15
-
# @parameter value [String] the raw header value.
16
-
definitialize(value)
15
+
# Multiple headers receive each value as a separate header entry on the wire, so this method takes a single string value and creates a new instance containing it.
16
+
#
17
+
# @parameter value [String] a single raw header value from the wire.
18
+
# @returns [Multiple] a new instance containing the parsed value.
19
+
defself.parse(value)
20
+
self.new([value])
21
+
end
22
+
23
+
# Coerces a value into a parsed header object.
24
+
#
25
+
# This method is used by the Headers class when setting values via `[]=` to convert application values into the appropriate policy type.
26
+
#
27
+
# @parameter value [String | Array] the value to coerce.
28
+
# @returns [Multiple] a parsed header object.
29
+
defself.coerce(value)
30
+
casevalue
31
+
whenArray
32
+
self.new(value)
33
+
else
34
+
self.parse(value.to_s)
35
+
end
36
+
end
37
+
38
+
# Initializes the multiple header with already-parsed values.
39
+
#
40
+
# @parameter value [Array | Nil] an array of header values, or `nil` for an empty header.
41
+
definitialize(value=nil)
17
42
super()
18
43
19
-
self << value
44
+
ifvalue
45
+
self.concat(value)
46
+
end
20
47
end
21
48
22
-
# Serializes the stored values into a newline-separated string.
49
+
# Converts the parsed header value into a raw wire-format string.
50
+
#
51
+
# Multiple headers are transmitted as separate header entries on the wire, so this serializes to a newline-separated string for storage.
23
52
#
24
-
# @returns [String] the serialized representation of the header values.
53
+
# @returns [String] a raw wire-format value (newline-separated string).
Copy file name to clipboardExpand all lines: lib/protocol/http/header/priority.rb
+6-5Lines changed: 6 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -12,16 +12,16 @@ module Header
12
12
#
13
13
# The `priority` header allows clients to express their preference for how resources should be prioritized by the server. It supports directives like `u=` to specify the urgency level of a request, and `i` to indicate whether a response can be delivered incrementally. The urgency levels range from 0 (highest priority) to 7 (lowest priority), while the `i` directive is a boolean flag.
14
14
classPriority < Split
15
-
# Initialize the priority header with the given value.
15
+
# Initializes the priority header with already-parsed and normalized values.
16
16
#
17
-
# @parameter value [String | Nil] the value of the priority header, if any. The value should be a comma-separated string of directives.
17
+
# @parameter value [Array | Nil] an array of normalized (lowercase) directives, or `nil` for an empty header.
18
18
definitialize(value=nil)
19
-
super(value&.downcase)
19
+
super(value&.map(&:downcase))
20
20
end
21
21
22
-
# Add a value to the priority header.
22
+
# Add a value to the priority header from a raw wire-format string.
23
23
#
24
-
# @parameter value [String] the directive to add to the header.
24
+
# @parameter value [String] a raw wire-format directive to add to the header.
0 commit comments