mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Add "headers" helper to make it easier to add headers to response.
This commit is contained in:
parent
c492ede5d3
commit
fbbb43dcab
2 changed files with 21 additions and 0 deletions
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue