From fc2f0d0dd26d777f134ba735589f6caf898bc892 Mon Sep 17 00:00:00 2001 From: Jan-Erik Rediger Date: Tue, 28 May 2024 20:50:45 +0200 Subject: [PATCH] handle request in function --- backend/cmd/httpd/main.ha | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/backend/cmd/httpd/main.ha b/backend/cmd/httpd/main.ha index 128f269..2fd4070 100644 --- a/backend/cmd/httpd/main.ha +++ b/backend/cmd/httpd/main.ha @@ -79,7 +79,7 @@ fn handle_req(arg: nullable *opaque) void = { switch (request.method) { case "GET" => switch (request.target.path) { - case "/" => handle_index(&buf, &serv_req.request); + case "/" => handle_index(&buf, serv_req); case => handle_notfound(&buf, serv_req); return; @@ -98,13 +98,6 @@ fn handle_req(arg: nullable *opaque) void = { handle_notfound(&buf, serv_req); return; }; - - http::response_write( - serv_req.socket, - http::STATUS_OK, - &buf, - ("Content-Type", "text/plain") - )!; }; export fn handle_notfound(buf: *io::stream, request: *http::server_request) void = { @@ -172,7 +165,9 @@ export fn handle_exec(buf: *io::stream, serv_req: *http::server_request) void = )!; }; -export fn handle_index(buf: *io::stream, request: *http::request) void = { +export fn handle_index(buf: *io::stream, serv_req: *http::server_request) void = { + let request = serv_req.request; + fmt::fprintfln(buf, "Method: {}", request.method)!; fmt::fprintfln(buf, "Path: {}", request.target.path)!; fmt::fprintfln(buf, "Fragment: {}", request.target.fragment)!; @@ -196,4 +191,11 @@ export fn handle_index(buf: *io::stream, request: *http::request) void = { }; fmt::fprintfln(buf, "EOF")!; }; + + http::response_write( + serv_req.socket, + http::STATUS_OK, + buf, + ("Content-Type", "text/plain") + )!; };