Commit ef08781ffd0b37c5f474513a6eba1dbeff4c006e

Thomas de Grivel 2024-08-08T11:40:00

public

diff --git a/lib/kc3/0.1/httpd.kc3 b/lib/kc3/0.1/httpd.kc3
index e08f424..c00df36 100644
--- a/lib/kc3/0.1/httpd.kc3
+++ b/lib/kc3/0.1/httpd.kc3
@@ -1,6 +1,6 @@
 defmodule HTTPd do
 
-  def root_dir = "."
+  def root_dir = "./public"
 
   def server = fn (host, port) {
     socket = Socket.listen(host, port)
@@ -81,13 +81,20 @@ defmodule HTTPd do
 
   def directory_page = fn (request) {
     files = File.list(root_dir + request.url)
-    file_li = fn (file) {
+    file_li = HTTPd.fn (file) {
       slash = if Str.ends_with?(request.url, "/") do "" else "/" end
-      "<li><a href=\"#{request.url}#{slash}#{file}\">#{request.url}#{slash}#{file}</a></li>"
+      real_path = "#{root_dir}#{request.url}#{slash}#{file}"
+      dir? = File.is_directory?(real_path)
+      path = "#{request.url}#{slash}#{file}"
+      mode = if dir? do "dr-xr-xr-x" else "-r--r--r--" end
+      "<li>#{mode} <a href=\"#{path}\">#{path}</a></li>"
     }
-    body = "<html>
+    body = """<html>
   <head>
     <title>Index of #{request.url}</title>
+    <style type="text/css">
+      ul { font-family: monospace; }        
+    </style>
   </head>
   <body>
     <h1>Index of #{request.url}</h1>
@@ -96,7 +103,7 @@ defmodule HTTPd do
     </ul>
   </body>
 </html>
-"
+"""
     %HTTP.Response{body: body}
   }
 
diff --git a/test/httpd/public/release b/test/httpd/public/release
new file mode 120000
index 0000000..2577df2
--- /dev/null
+++ b/test/httpd/public/release
@@ -0,0 +1 @@
+../../../release
\ No newline at end of file
diff --git a/test/httpd/public/test.txt b/test/httpd/public/test.txt
new file mode 100644
index 0000000..85cad51
--- /dev/null
+++ b/test/httpd/public/test.txt
@@ -0,0 +1,3 @@
+Test
+
+OK !
diff --git a/test/httpd/release b/test/httpd/release
deleted file mode 120000
index 8caa4cf..0000000
--- a/test/httpd/release
+++ /dev/null
@@ -1 +0,0 @@
-../../release
\ No newline at end of file
diff --git a/test/httpd/test.html b/test/httpd/test.html
deleted file mode 100644
index e2f733c..0000000
--- a/test/httpd/test.html
+++ /dev/null
@@ -1,13 +0,0 @@
-<!doctype html>
-<html>
-  <head>
-    <title>HTML test</title>
-  </head>
-  <body>
-    <h1>HTML test</h1>
-
-    <p>
-      Test <span style="color: #0f0;"><b>OK</b></span> !
-    </p>
-  </body>
-</html>
diff --git a/test/httpd/test.txt b/test/httpd/test.txt
deleted file mode 100644
index 85cad51..0000000
--- a/test/httpd/test.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-Test
-
-OK !