Skip to content

Commit f4da23f

Browse files
committed
Add conformance test for request headers.
1 parent e2382a1 commit f4da23f

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

lib/rack/conform/application.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def test_cookies(env)
4848
end.finish
4949
end
5050

51-
def test_headers(env)
51+
def test_headers_response(env)
5252
headers = JSON.parse(env['rack.input'].read)
5353

5454
Rack::Response.new.tap do |response|
@@ -60,6 +60,12 @@ def test_headers(env)
6060
end.finish
6161
end
6262

63+
def test_headers_request(env)
64+
headers = env.select{|key, value| key.start_with?('HTTP_')}
65+
66+
[200, {}, [JSON.generate(headers)]]
67+
end
68+
6369
def test_streaming_hijack(env)
6470
if env['rack.hijack?']
6571
callback = proc do |stream|

test/rack/conform/headers.rb

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,32 @@
66
require 'client_context'
77
include ClientContext
88

9-
def body(headers)
10-
Protocol::HTTP::Body::Buffered.wrap(JSON.generate(headers))
9+
with 'response headers' do
10+
def body(headers)
11+
Protocol::HTTP::Body::Buffered.wrap(JSON.generate(headers))
12+
end
13+
14+
it 'can echo back headers' do
15+
response = client.get("/headers/response", {}, body({'content-type' => 'text/plain'}))
16+
17+
expect(response.status).to be == 200
18+
expect(response.headers).to have_keys(
19+
'content-type' => be == 'text/plain'
20+
)
21+
ensure
22+
response&.finish
23+
end
1124
end
1225

13-
it 'can echo back headers' do
14-
response = client.get("/headers", {}, body({'content-type' => 'text/plain'}))
15-
16-
expect(response.status).to be == 200
17-
expect(response.headers).to have_keys(
18-
'content-type' => be == 'text/plain'
19-
)
20-
ensure
21-
response&.finish
26+
with 'request headers' do
27+
it 'can echo back headers with multiple set-cookie values' do
28+
response = client.get("/headers/request", [['set-cookie', 'a=1'], ['set-cookie', 'b=2']])
29+
30+
expect(response.status).to be == 200
31+
headers = JSON.parse(response.read)
32+
33+
expect(headers).to have_keys(
34+
'HTTP_SET_COOKIE' => be == "a=1;b=2"
35+
)
36+
end
2237
end

0 commit comments

Comments
 (0)