From e49c1825e9de214dc0d35f366fc2ced5ab40580b Mon Sep 17 00:00:00 2001 From: Daniel Westendorf Date: Thu, 8 May 2025 14:04:20 -0600 Subject: [PATCH 1/2] Add a failing test --- test/protocol/http/headers.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/protocol/http/headers.rb b/test/protocol/http/headers.rb index 20b6b0b..35ca16d 100644 --- a/test/protocol/http/headers.rb +++ b/test/protocol/http/headers.rb @@ -13,7 +13,8 @@ ["Set-Cookie", "hello=world"], ["Accept", "*/*"], ["set-cookie", "foo=bar"], - ["connection", "Keep-Alive"] + ["connection", "Keep-Alive"], + ["X-Foo", 1] ] end @@ -29,7 +30,7 @@ with "#keys" do it "should return keys" do - expect(headers.keys).to be == ["content-type", "set-cookie", "accept", "connection"] + expect(headers.keys).to be == ["content-type", "set-cookie", "accept", "connection", "x-foo"] end end @@ -55,7 +56,8 @@ "content-type" => "text/plain", "set-cookie" => ["hello=world", "foo=bar", "goodbye=world"], "accept" => ["*/*"], - "connection" => ["keep-alive"] + "connection" => ["keep-alive"], + "x-foo" => ["1"] } end end From 7e2d56c648dfb5844b69313385d5fa06c5244543 Mon Sep 17 00:00:00 2001 From: Daniel Westendorf Date: Thu, 8 May 2025 14:17:27 -0600 Subject: [PATCH 2/2] Cast value to string if it isn't a string or nil --- lib/protocol/http/header/split.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/protocol/http/header/split.rb b/lib/protocol/http/header/split.rb index 4ecb1f1..d2c6537 100644 --- a/lib/protocol/http/header/split.rb +++ b/lib/protocol/http/header/split.rb @@ -17,10 +17,13 @@ class Split < Array # # @parameter value [String | Nil] the raw header value containing multiple entries separated by commas, or `nil` for an empty header. def initialize(value = nil) - if value + case value + when String super(value.split(COMMA)) + when nil + super() else - super() + super([value.to_s]) end end