Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/rack/conform/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,14 @@ def test_echo(env)
end

def test_cookies(env)
cookies = JSON.parse(env['rack.input'].read)
request = Rack::Request.new(env)
cookies = request.cookies

Rack::Response.new.tap do |response|
# Hex encode non-printable characters:
value = env['HTTP_COOKIE'].gsub(/[^[:print:]]/, &:ord)
response.add_header('x-http-cookie', value)

cookies.each do |key, value|
response.set_cookie(key, value)
end
Expand Down
20 changes: 17 additions & 3 deletions test/rack/conform/cookies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,35 @@ def body(headers)
end

it 'can respond with a single cookie' do
response = client.get("/cookies", {}, body({'a' => 1}))
response = client.get("/cookies", [['cookie', 'a=1']])

expect(response.status).to be == 200
expect(response.headers).to have_keys(
'x-http-cookie' => be == ['a=1'],
'set-cookie' => be == ['a=1']
)
ensure
response&.finish
end

it 'can respond with multiple cookies' do
response = client.get("/cookies", {}, body({'a' => 1, 'b' => 2}))
it 'can respond with multiple combined cookies' do
response = client.get("/cookies", [['cookie', 'a=1;b=2']])

expect(response.status).to be == 200
expect(response.headers).to have_keys(
'x-http-cookie' => be == ['a=1;b=2'],
'set-cookie' => be == ["a=1", "b=2"]
)
ensure
response&.finish
end

it 'can respond with multiple cookie headers' do
response = client.get("/cookies", [['cookie', 'a=1'], ['cookie', 'b=2']])

expect(response.status).to be == 200
expect(response.headers).to have_keys(
'x-http-cookie' => be == ['a=1;b=2'],
'set-cookie' => be == ['a=1', 'b=2']
)
ensure
Expand Down