diff --git a/.travis.yml b/.travis.yml index 9dfb8c5..fd4072e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,3 +5,5 @@ crystal: matrix: allow_failures: - crystal: nightly +os: + - osx diff --git a/spec/kemal_handler_spec.cr b/spec/kemal_handler_spec.cr index b4e6107..ed423fa 100644 --- a/spec/kemal_handler_spec.cr +++ b/spec/kemal_handler_spec.cr @@ -102,4 +102,11 @@ describe "Kemal::Handler" do response = kemal.call(request) response.body.should eq("Skills ruby,crystal") end + + it "renders 404 on not found" do + kemal = Kemal::Handler.new + request = HTTP::Request.new("GET", "/?message=world") + response = kemal.call(request) + response.body.should eq("hello world") + end end diff --git a/src/images/404.png b/src/images/404.png new file mode 100644 index 0000000..2db94c7 Binary files /dev/null and b/src/images/404.png differ diff --git a/src/kemal/handler.cr b/src/kemal/handler.cr index 0333e20..0e46bb4 100644 --- a/src/kemal/handler.cr +++ b/src/kemal/handler.cr @@ -6,6 +6,7 @@ class Kemal::Handler < HTTP::Handler def initialize @routes = [] of Route + @match = false end def call(request) @@ -20,7 +21,7 @@ class Kemal::Handler < HTTP::Handler def process_request(request) @routes.each do |route| match = route.match?(request) - if match + if @match = match params = Kemal::ParamParser.new(route, request).parse context = Context.new(request, params) begin @@ -31,6 +32,28 @@ class Kemal::Handler < HTTP::Handler end end end + unless @match + return HTTP::Response.new(404, not_found) + end nil end + + def not_found + <<-HTML + + +
+ + + +