-
-
Notifications
You must be signed in to change notification settings - Fork 185
/
init_handler_spec.cr
44 lines (40 loc) · 1.72 KB
/
init_handler_spec.cr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
require "./spec_helper"
describe "Kemal::InitHandler" do
it "initializes context with Content-Type: text/html" do
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.next = ->(_context : HTTP::Server::Context) {}
Kemal::InitHandler::INSTANCE.call(context)
context.response.headers["Content-Type"].should eq "text/html"
end
it "initializes context with Date header" do
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.next = ->(_context : HTTP::Server::Context) {}
Kemal::InitHandler::INSTANCE.call(context)
date = context.response.headers["Date"]?.should_not be_nil
date = HTTP.parse_time(date).should_not be_nil
date.should be_close(Time.utc, 1.second)
end
it "initializes context with X-Powered-By: Kemal" do
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 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