Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/protocol/http/headers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ def flatten
# @attribute [Array] An array of `[key, value]` pairs.
attr :fields

# @returns [Array] The fields of the headers.
def to_a
@fields
end

# @returns [Boolean] Whether there are any trailers.
def trailer?
@tail != nil
Expand Down
4 changes: 4 additions & 0 deletions releases.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Releases

## Unreleased

- Add `Protocol::HTTP::Headers#to_a` method that returns the fields array, providing compatibility with standard Ruby array conversion pattern.

## v0.51.0

- `Protocol::HTTP::Headers` now raise a `DuplicateHeaderError` when a duplicate singleton header (e.g. `content-length`) is added.
Expand Down
14 changes: 14 additions & 0 deletions test/protocol/http/headers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,20 @@
end
end

with "#to_a" do
it "should return the fields array" do
expect(headers.to_a).to be == fields
end

it "should return the same object as fields" do
expect(headers.to_a).to be_equal(headers.fields)
end

it "should return an array" do
expect(headers.to_a).to be_a(Array)
end
end

with "#to_h" do
it "should generate array values for duplicate keys" do
expect(headers.to_h["set-cookie"]).to be == ["hello=world", "foo=bar"]
Expand Down
Loading