Commit 69d0b3c71b6114ab50dc74bacb810f80cfe7f84c

Thomas de Grivel 2024-08-12T12:01:11

wip httpd

diff --git a/lib/kc3/0.1/httpd.kc3 b/lib/kc3/0.1/httpd.kc3
index aa0d3eb..5617dd6 100644
--- a/lib/kc3/0.1/httpd.kc3
+++ b/lib/kc3/0.1/httpd.kc3
@@ -12,9 +12,20 @@ defmodule HTTPd do
   def root_dir = "./public"
 
   def http_client = fn (socket, events, client_ev, client) do
-    puts("echo_client")
+    puts("http_client")
     if List.has?(events, :read) do
-      server_client(client)
+      puts("http_client: read")
+      puts("HTTPd.server_loop: got client #{client}")
+      req = HTTP.Request.buf_parse(client.buf_rw.r)
+      puts("http_client: req: #{req}")
+      if req do
+        router = route_request(req)
+        res = router(req)
+        puts("http_client: res: #{res}")
+        r = HTTP.Response.buf_write(res, client.buf_rw.w,
+          req.method != :head)
+        puts("http_client: wrote #{r}")
+      end
     end
   end
 
@@ -50,16 +61,6 @@ defmodule HTTPd do
     Socket.close(%Socket{fd: socket})
   }
 
-  def server_client = fn (client) {
-    puts("HTTPd.server_loop: got client #{client}")
-    req = HTTP.Request.buf_parse(client.buf_rw.r)
-    if req do
-      router = route_request(req)
-      res = router(req)
-      HTTP.Response.buf_write(res, client.buf_rw.w, req.method != :head)
-    end
-  }
-
   def main = fn {
     () {
       HTTP.mime_type_load("mime.types")