diff --git a/spec/kemal_handler_spec.cr b/spec/kemal_handler_spec.cr index 4b0e869..3201895 100644 --- a/spec/kemal_handler_spec.cr +++ b/spec/kemal_handler_spec.cr @@ -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 diff --git a/src/kemal/handler.cr b/src/kemal/handler.cr index 3becf36..2d30080 100644 --- a/src/kemal/handler.cr +++ b/src/kemal/handler.cr @@ -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)