File tree Expand file tree Collapse file tree 3 files changed +23
-0
lines changed Expand file tree Collapse file tree 3 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -108,6 +108,11 @@ def flatten
108
108
# @attribute [Array] An array of `[key, value]` pairs.
109
109
attr :fields
110
110
111
+ # @returns [Array] The fields of the headers.
112
+ def to_a
113
+ @fields
114
+ end
115
+
111
116
# @returns [Boolean] Whether there are any trailers.
112
117
def trailer?
113
118
@tail != nil
Original file line number Diff line number Diff line change 1
1
# Releases
2
2
3
+ ## Unreleased
4
+
5
+ - Add ` Protocol::HTTP::Headers#to_a ` method that returns the fields array, providing compatibility with standard Ruby array conversion pattern.
6
+
3
7
## v0.51.0
4
8
5
9
- ` Protocol::HTTP::Headers ` now raise a ` DuplicateHeaderError ` when a duplicate singleton header (e.g. ` content-length ` ) is added.
Original file line number Diff line number Diff line change 148
148
end
149
149
end
150
150
151
+ with "#to_a" do
152
+ it "should return the fields array" do
153
+ expect ( headers . to_a ) . to be == fields
154
+ end
155
+
156
+ it "should return the same object as fields" do
157
+ expect ( headers . to_a ) . to be_equal ( headers . fields )
158
+ end
159
+
160
+ it "should return an array" do
161
+ expect ( headers . to_a ) . to be_a ( Array )
162
+ end
163
+ end
164
+
151
165
with "#to_h" do
152
166
it "should generate array values for duplicate keys" do
153
167
expect ( headers . to_h [ "set-cookie" ] ) . to be == [ "hello=world" , "foo=bar" ]
You can’t perform that action at this time.
0 commit comments