Ability to optionally disable powered-by header (#449)

This commit is contained in:
Blacksmoke16 2018-05-09 03:19:59 -04:00 committed by Serdar Dogruyol
parent 73045bb138
commit f3f7e319ae
4 changed files with 16 additions and 1 deletions

View file

@ -17,6 +17,10 @@ describe "Config" do
config.env.should eq "production"
end
it "sets default powered_by_header to true" do
Kemal.config.powered_by_header.should be_true
end
it "sets host binding" do
config = Kemal.config
config.host_binding = "127.0.0.1"

View file

@ -19,4 +19,14 @@ describe "Kemal::InitHandler" do
Kemal::InitHandler::INSTANCE.call(context)
context.response.headers["X-Powered-By"].should eq "Kemal"
end
it "does not initialize context with X-Powered-By: Kemal if disabled" do
Kemal.config.powered_by_header = false
request = HTTP::Request.new("GET", "/")
io = IO::Memory.new
response = HTTP::Server::Response.new(io)
context = HTTP::Server::Context.new(request, response)
Kemal::InitHandler::INSTANCE.call(context)
context.response.headers["X-Powered-By"]?.should be_nil
end
end