Merge pull request #165 from MGerrior/add_headers_helper_method

Add headers helper method
This commit is contained in:
Serdar Dogruyol 2016-06-16 17:35:38 +03:00 committed by GitHub
commit 56067b6280
2 changed files with 21 additions and 0 deletions

View file

@ -67,4 +67,21 @@ describe "Macros" do
client_response.body.should eq("") client_response.body.should eq("")
end end
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 end

View file

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