Skip to content

Commit 6b347bb

Browse files
Add tests for make_response header handling.
1 parent b07add0 commit 6b347bb

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

lib/protocol/rack/adapter/rack3.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ def self.make_response(env, response)
130130
# Force streaming response:
131131
body = body.method(:call)
132132
end
133+
134+
headers.transform_values! do |value|
135+
if value.is_a?(Array) and value.size == 1
136+
value.first
137+
else
138+
value
139+
end
140+
end
133141

134142
[response.status, headers, body]
135143
end

test/protocol/rack/adapter.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,27 @@
5050
expect(body).to be(:respond_to?, :call)
5151
end
5252
end
53+
54+
it "can wrap headers" do
55+
response = Protocol::HTTP::Response[200, headers: {"x-custom" => "123"}, body: ["Hello World!"]]
56+
status, headers, body = subject.make_response(env, response)
57+
58+
expect(headers["x-custom"]).to be == "123"
59+
end
60+
61+
it "can wrap multi-value headers" do
62+
response = Protocol::HTTP::Response[200, headers: {"set-cookie" => ["a=b", "x=y"]}, body: ["Hello World!"]]
63+
64+
status, headers, body = subject.make_response(env, response)
65+
66+
set_cookie = headers["set-cookie"]
67+
68+
if subject::VERSION < "3"
69+
expect(set_cookie).to be == "a=b\nx=y"
70+
else
71+
expect(set_cookie).to be == ["a=b", "x=y"]
72+
end
73+
end
5374
end
5475

5576
AnApplication = Sus::Shared("an application") do

0 commit comments

Comments
 (0)