From 8998860f3d2faf0441c9e6f08d20f1497c3082b8 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Mon, 18 Aug 2025 11:53:00 +1200 Subject: [PATCH 1/3] Add Headers#to_a method - Adds Headers#to_a method that returns the fields array - Provides compatibility with standard Ruby array conversion pattern - Includes comprehensive tests for the new method --- lib/protocol/http/headers.rb | 5 +++++ test/protocol/http/headers.rb | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/protocol/http/headers.rb b/lib/protocol/http/headers.rb index 2080353..69e386b 100644 --- a/lib/protocol/http/headers.rb +++ b/lib/protocol/http/headers.rb @@ -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 diff --git a/test/protocol/http/headers.rb b/test/protocol/http/headers.rb index dbb0955..3bb150f 100644 --- a/test/protocol/http/headers.rb +++ b/test/protocol/http/headers.rb @@ -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"] From e8d86c9b7ba73a612104dd4ed4de56db76e22127 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Mon, 18 Aug 2025 16:07:50 +1200 Subject: [PATCH 2/3] Update releases.md with Headers#to_a method - Add entry for v0.52.0 documenting the new to_a method --- releases.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/releases.md b/releases.md index d9f4b48..001cf6d 100644 --- a/releases.md +++ b/releases.md @@ -1,5 +1,9 @@ # Releases +## v0.52.0 + + - 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. From f00a20c6cfd356ce7e18e9f3a995c075131a98fd Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Mon, 18 Aug 2025 16:08:25 +1200 Subject: [PATCH 3/3] Update releases.md to use 'Unreleased' section - Change version header from v0.52.0 to 'Unreleased' for better release management --- releases.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/releases.md b/releases.md index 001cf6d..20ddb4f 100644 --- a/releases.md +++ b/releases.md @@ -1,6 +1,6 @@ # Releases -## v0.52.0 +## Unreleased - Add `Protocol::HTTP::Headers#to_a` method that returns the fields array, providing compatibility with standard Ruby array conversion pattern.