implemented 404 page
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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
diff --git a/lib/kc3/0.1/httpd.kc3 b/lib/kc3/0.1/httpd.kc3
index 5e87b7b..1f207e1 100644
--- a/lib/kc3/0.1/httpd.kc3
+++ b/lib/kc3/0.1/httpd.kc3
@@ -16,7 +16,27 @@ defmodule HTTPd do
req = HTTP.Request.buf_parse(client.buf_rw.r)
if req do
puts("HTTPd.server_loop: got request #{req}")
- res = %HTTP.Response{body: "<html>
+ router = route_request(req)
+ puts("HTTPd.server_loop: router: #{router}")
+ res = router(req)
+ puts("HTTPd.server_loop: response: #{res}")
+ HTTP.Response.buf_write(res, client.buf_rw.w)
+ end
+ }
+
+ def main = fn {
+ () {
+ host = getenv("KC3_HTTPD_HOST")
+ port = getenv("KC3_HTTPD_PORT")
+ server(host, port)
+ }
+ (host, port) {
+ server(host, port)
+ }
+ }
+
+ def debug_page = fn (request) {
+ body = "<html>
<head>
<title>KC3 HTTPd</title>
<style>
@@ -38,21 +58,28 @@ defmodule HTTPd do
<pre><code>#{req}</code></pre>
</body>
</html>
-"}
- puts("HTTPd.server_loop: response: #{res}")
- HTTP.Response.buf_write(res, client.buf_rw.w)
- end
+"
+ %HTTP.Response{body: body}
}
- def main = fn {
- () {
- host = getenv("KC3_HTTPD_HOST")
- port = getenv("KC3_HTTPD_PORT")
- server(host, port)
- }
- (host, port) {
- server(host, port)
- }
+ def error_404_page = fn (request) {
+ body = "<html>
+ <head>
+ <title>404 Not Found</title>
+ </head>
+ <body>
+ <h1>404 Not Found</h1>
+ <p>
+ The requested URL #{request.url} was not found on this server.
+ </p>
+ </body>
+</html>
+"
+ %HTTP.Response{code: 404, body: body}
+ }
+
+ def route_request = fn (request) {
+ error_404_page
}
end