2016-07-17 15:11:26 +00:00
|
|
|
require "./spec_helper"
|
|
|
|
|
|
|
|
describe "Kemal::InitHandler" do
|
|
|
|
it "initializes context with Content-Type: text/html" do
|
|
|
|
request = HTTP::Request.new("GET", "/")
|
2016-11-22 20:29:10 +00:00
|
|
|
io = IO::Memory.new
|
2016-07-17 15:11:26 +00:00
|
|
|
response = HTTP::Server::Response.new(io)
|
|
|
|
context = HTTP::Server::Context.new(request, response)
|
2018-05-17 08:07:40 +00:00
|
|
|
Kemal::InitHandler::INSTANCE.next = ->(_context : HTTP::Server::Context) {}
|
2016-07-17 15:11:26 +00:00
|
|
|
Kemal::InitHandler::INSTANCE.call(context)
|
|
|
|
context.response.headers["Content-Type"].should eq "text/html"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "initializes context with X-Powered-By: Kemal" do
|
|
|
|
request = HTTP::Request.new("GET", "/")
|
2016-11-22 20:29:10 +00:00
|
|
|
io = IO::Memory.new
|
2016-07-17 15:11:26 +00:00
|
|
|
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 eq "Kemal"
|
|
|
|
end
|
2018-05-09 07:19:59 +00:00
|
|
|
|
|
|
|
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
|
2016-07-17 15:11:26 +00:00
|
|
|
end
|