diff options
author | Runxi Yu <me@runxiyu.org> | 2025-03-13 08:52:03 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-03-13 08:52:03 +0800 |
commit | 1ca7ae3859b2c0397e4b28f77c04a4b816f69ae1 (patch) | |
tree | dbd0c14ebacb5ab2c27e0817455c2649da849136 /main.ha | |
parent | Use for each loops (diff) | |
download | forge-1ca7ae3859b2c0397e4b28f77c04a4b816f69ae1.tar.gz forge-1ca7ae3859b2c0397e4b28f77c04a4b816f69ae1.tar.zst forge-1ca7ae3859b2c0397e4b28f77c04a4b816f69ae1.zip |
Begin to use hare-htmpl
Diffstat (limited to '')
-rw-r--r-- | main.ha | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -3,6 +3,7 @@ // Adapted from template by Willow Barraco <contact@willowbarraco.fr> use getopt; +use htmpl; use log; use net; use net::ip; @@ -17,7 +18,7 @@ use strings; const usage: [_]getopt::help = [ "HTTP server", - ('a', "address", "listened address (ex: 127.0.0.1:8080)") + ('a', "address", "listened address") ]; export fn main() void = { @@ -63,9 +64,10 @@ export fn main() void = { }; }; -export fn handlereq(conn: io::handle, request: *http::request) (void | io::error) = { - fmt::fprint(conn, "HTTP/1.1 200 OK\r\n")?; - fmt::fprint(conn, "Content-Type: text/plain\r\n\r\n")?; - - fmt::fprintln(conn, "Hi there!")?; +export fn handlereq(conn: io::handle, request: *http::request) (void | io::error | nomem) = { + htmpl::write(conn, "HTTP/1.1 200 OK\r\n")?; + htmpl::write(conn, "Content-Type: text/html\r\n\r\n")?; + htmpl::write(conn, "<!DOCTYPE html><html><body><h1>")?; + htmpl::write_escape_html(conn, "Hey there <3")?; + htmpl::write(conn, "</h1></body></html>")?; }; |