Skip to content

Commit

Permalink
Merge pull request #165 from MGerrior/add_headers_helper_method
Browse files Browse the repository at this point in the history
Add headers helper method
  • Loading branch information
Serdar Dogruyol committed Jun 16, 2016
2 parents c492ede + fbbb43d commit 56067b6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
17 changes: 17 additions & 0 deletions spec/helpers_spec.cr
Expand Up @@ -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
4 changes: 4 additions & 0 deletions src/kemal/helpers.cr
Expand Up @@ -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

0 comments on commit 56067b6

Please sign in to comment.