Skip to content

Commit c747963

Browse files
Fix header tests.
1 parent da66651 commit c747963

File tree

4 files changed

+12
-15
lines changed

4 files changed

+12
-15
lines changed

lib/protocol/rack/adapter/rack2.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,11 @@ def self.make_response(env, response)
165165
end
166166

167167
headers.transform_values! do |value|
168-
value.is_a?(Array) ? value.join("\n") : value
168+
if value.is_a?(Array)
169+
value.join("\n")
170+
else
171+
value
172+
end
169173
end
170174

171175
[response.status, headers, body]

lib/protocol/rack/adapter/rack3.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,6 @@ 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
141133

142134
[response.status, headers, body]
143135
end

test/protocol/rack/adapter.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,22 @@
5555
response = Protocol::HTTP::Response[200, headers: {"x-custom" => "123"}, body: ["Hello World!"]]
5656
status, headers, body = subject.make_response(env, response)
5757

58-
expect(headers["x-custom"]).to be == "123"
58+
x_custom = headers["x-custom"]
59+
60+
expect(x_custom).to (be == "123").or(be == ["123"])
5961
end
6062

6163
it "can wrap multi-value headers" do
62-
response = Protocol::HTTP::Response[200, headers: {"set-cookie" => ["a=b", "x=y"]}, body: ["Hello World!"]]
64+
response = Protocol::HTTP::Response[200, headers: [["x-custom", "a=b"], ["x-custom", "x=y"]], body: ["Hello World!"]]
6365

6466
status, headers, body = subject.make_response(env, response)
6567

66-
set_cookie = headers["set-cookie"]
68+
x_custom = headers["x-custom"]
6769

6870
if subject::VERSION < "3"
69-
expect(set_cookie).to be == "a=b\nx=y"
71+
expect(x_custom).to be == "a=b\nx=y"
7072
else
71-
expect(set_cookie).to be == ["a=b", "x=y"]
73+
expect(x_custom).to be == ["a=b", "x=y"]
7274
end
7375
end
7476
end

test/protocol/rack/adapter/rack31.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# Copyright, 2025, by Samuel Williams.
55

66
require "sus/fixtures/console"
7-
require "rack/mock_request"
87

98
require "protocol/http/request"
109
require "protocol/rack/adapter/rack31"

0 commit comments

Comments
 (0)