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 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