This commit is contained in:
Sdogruyol 2015-11-27 22:45:13 +02:00
parent 9a5934811d
commit 58013ba005
4 changed files with 33 additions and 1 deletions

View File

@ -5,3 +5,5 @@ crystal:
matrix:
allow_failures:
- crystal: nightly
os:
- osx

View File

@ -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

BIN
src/images/404.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View File

@ -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
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body { text-align:center;font-family:helvetica,arial;font-size:22px;
color:#888;margin:20px}
#c {margin:0 auto;width:500px;text-align:left}
</style>
</head>
<body>
<h2>Kemal doesn't know this way.</h2>
<img src="/images/404.png">
</body>
</html>
HTML
end
end