Skip to content

Commit e88e803

Browse files
committed
Correct Header::Cookie#to_s.
1 parent 9a7f4da commit e88e803

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

lib/protocol/http/header/cookie.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ def to_h
2424
cookies.map{|cookie| [cookie.name, cookie]}.to_h
2525
end
2626

27+
# Serializes the `cookie` header by joining individual cookie strings with semicolons.
28+
def to_s
29+
join(";")
30+
end
31+
2732
# Whether this header is acceptable in HTTP trailers.
2833
# Cookie headers should not appear in trailers as they contain state information needed early in processing.
2934
# @returns [Boolean] `false`, as cookie headers are needed during initial request processing.

test/protocol/http/header/cookie.rb

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@
3232
directives: be == {"path" => "/", "secure" => true},
3333
)
3434
end
35-
36-
it "has string representation" do
37-
session = cookies["session"]
38-
expect(session.to_s).to be == "session=123;path=/;secure"
39-
end
4035
end
4136

4237
with "session=abc123; secure" do
@@ -50,10 +45,19 @@
5045
)
5146
expect(session.directives).to have_keys("secure")
5247
end
48+
end
49+
50+
with "multiple cookies" do
51+
let(:header) do
52+
cookie = subject.new
53+
cookie << "session=abc123"
54+
cookie << "user_id=42"
55+
cookie << "token=xyz789"
56+
cookie
57+
end
5358

54-
it "has string representation" do
55-
session = cookies["session"]
56-
expect(session.to_s).to be == "session=abc123;secure"
59+
it "joins cookies with semicolons without spaces" do
60+
expect(header.to_s).to be == "session=abc123;user_id=42;token=xyz789"
5761
end
5862
end
5963
end

0 commit comments

Comments
 (0)