Skip to content

Add conformance test for request headers. #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
8 changes: 7 additions & 1 deletion lib/rack/conform/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_cookies(env)
end.finish
end

def test_headers(env)
def test_headers_response(env)
headers = JSON.parse(env['rack.input'].read)

Rack::Response.new.tap do |response|
Expand All @@ -60,6 +60,12 @@ def test_headers(env)
end.finish
end

def test_headers_request(env)
headers = env.select{|key, value| key.start_with?('HTTP_')}

[200, {}, [JSON.generate(headers)]]
end

def test_streaming_hijack(env)
if env['rack.hijack?']
callback = proc do |stream|
Expand Down
37 changes: 26 additions & 11 deletions test/rack/conform/headers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,32 @@
require 'client_context'
include ClientContext

def body(headers)
Protocol::HTTP::Body::Buffered.wrap(JSON.generate(headers))
with 'response headers' do
def body(headers)
Protocol::HTTP::Body::Buffered.wrap(JSON.generate(headers))
end

it 'can echo back headers' do
response = client.get("/headers/response", {}, body({'content-type' => 'text/plain'}))

expect(response.status).to be == 200
expect(response.headers).to have_keys(
'content-type' => be == 'text/plain'
)
ensure
response&.finish
end
end

it 'can echo back headers' do
response = client.get("/headers", {}, body({'content-type' => 'text/plain'}))

expect(response.status).to be == 200
expect(response.headers).to have_keys(
'content-type' => be == 'text/plain'
)
ensure
response&.finish
with 'request headers' do
it 'can echo back headers with multiple set-cookie values' do
response = client.get("/headers/request", [['set-cookie', 'a=1'], ['set-cookie', 'b=2']])

expect(response.status).to be == 200
headers = JSON.parse(response.read)

expect(headers).to have_keys(
'HTTP_SET_COOKIE' => be == "a=1;b=2"
)
end
end
Loading