Merge pull request #20 from ilatif/master

Implemented HTTP `HEAD` method.
This commit is contained in:
Serdar Dogruyol 2015-12-04 16:38:13 +02:00
commit a37d45cd22
2 changed files with 20 additions and 0 deletions

View file

@ -167,4 +167,21 @@ describe "Kemal::Handler" do
response.body.should eq("Hello World from DELETE")
end
it "can process HTTP HEAD requests for defined GET routes" do
kemal = Kemal::Handler.new
kemal.add_route "GET", "/" do |env|
"Hello World from GET"
end
request = HTTP::Request.new("HEAD", "/")
response = kemal.call(request)
response.status_code.should eq(200)
end
it "can't process HTTP HEAD requests for undefined GET routes" do
kemal = Kemal::Handler.new
request = HTTP::Request.new("HEAD", "/")
response = kemal.call(request)
response.status_code.should eq(404)
end
end

View file

@ -15,6 +15,9 @@ class Kemal::Handler < HTTP::Handler
def add_route(method, path, &handler : Kemal::Context -> _)
@routes << Route.new(method, path, &handler)
# Registering HEAD route for defined GET routes.
@routes << Route.new("HEAD", path, &handler) if method == "GET"
end
def process_request(request)