Add "headers" helper to make it easier to add headers to response.

This commit is contained in:
Matthew Gerrior 2016-06-16 10:05:28 -04:00
parent c492ede5d3
commit fbbb43dcab
2 changed files with 21 additions and 0 deletions

View File

@ -67,4 +67,21 @@ describe "Macros" do
client_response.body.should eq("")
end
end
describe "#headers" do
it "can add headers" do
get "/headers" do |env|
env.response.headers.add "Content-Type", "image/png"
headers env, {
"Access-Control-Allow-Origin" => "*",
"Content-Type" => "text/plain"
}
end
request = HTTP::Request.new("GET", "/headers")
response = call_request_on_app(request)
response.headers["Access-Control-Allow-Origin"].should eq("*")
response.headers["Content-Type"].should eq("text/plain")
end
end
end

View File

@ -57,3 +57,7 @@ end
def serve_static(status)
Kemal.config.serve_static = status
end
def headers(env, additional_headers)
env.response.headers.merge!(additional_headers)
end