Commit 9b1430ede9db2d254e527056b7ec0b72a2597f25

jeanne 2024-10-15T14:02:27

wip httpd: partials range request

diff --git a/.ikc3_history b/.ikc3_history
index 64049b5..ac70936 100644
--- a/.ikc3_history
+++ b/.ikc3_history
@@ -1,12 +1,3 @@
-def op = %KC3.Operator{sym: :****, symbol_value: fn (a, b) { a * b * 4 }}
-3 **** 4
-3 * 4 * 4
-Sh.escape("abc")
-Sh.escape("abc;")
-puts(Sh.escape("abc;"))
-puts(Sh.escape("abc"))
-puts(Sh.escape("ab c"))
-puts(Sh.escape("ab(c"))
 puts(Sh.escape("abc"))
 1 + 1
 1 + 10000000000000000000000000000000000000000000000000
@@ -97,3 +88,12 @@ def op_muul = %KC3.Operator{sym: :////, symbol_value: fn (a, b) { (a - b) * 4 }}
 a
 b
 c
+Compare.str_case_insensitive("Range", "range")
+!Compare.str_case_insensitive("Range", "range")
+! Compare.str_case_insensitive("Range", "range")
+! 0
+quit
+q
+exit
+exit(Ã)
+exit()
diff --git a/lib/kc3/0.1/compare.kc3 b/lib/kc3/0.1/compare.kc3
new file mode 100644
index 0000000..fccc8c8
--- /dev/null
+++ b/lib/kc3/0.1/compare.kc3
@@ -0,0 +1,5 @@
+defmodule Compare do
+
+  def str_case_insensitive = cfn S8 "compare_str_case_insensitive" (Str, Str)
+
+end
diff --git a/lib/kc3/0.1/httpd.kc3 b/lib/kc3/0.1/httpd.kc3
index a18ed34..6020e33 100644
--- a/lib/kc3/0.1/httpd.kc3
+++ b/lib/kc3/0.1/httpd.kc3
@@ -39,6 +39,8 @@ defmodule HTTPd do
           "Keep-Alive", "timeout=5, max=1000")
         response = HTTP.Response.set_header(response,
           "Server", "kc3_httpd")
+        response = HTTP.Response.set_header(response,
+          "Accept-Ranges", "bytes")
         r = HTTP.Response.buf_write(response, client.buf_rw.w,
           req.method != HEAD)
         client_addr = if client.addr_str != "127.0.0.1" do
@@ -274,6 +276,12 @@ defmodule HTTPd do
         mime = HTTP.mime_type(ext)
         stat = File.stat(path)
         last_modified = Str.ftime(stat.st_mtim, "%a, %d %b %G %T %Z")
+        range = List.find_if(request.headers, fn ({header_name, header_value}) do
+          if ! Compare.str_case_insensitive("Range", header_name) do
+            header_value
+          end
+        end)
+        puts("Range: #{inspect(range)}")
         headers = [{"Content-Type", (Str) mime},
                    {"Content-Length", (Str) stat.st_size},
                    {"Last-Modified", last_modified}]
diff --git a/lib/kc3/0.1/list.kc3 b/lib/kc3/0.1/list.kc3
index 2fad4e0..a72eb3f 100644
--- a/lib/kc3/0.1/list.kc3
+++ b/lib/kc3/0.1/list.kc3
@@ -9,6 +9,18 @@ defmodule List do
     ([a | b], f) { f(a); each(b, f) }
   }
 
+  def find_if = fn {
+    ([], _) { false }
+    ([a | b], f) do
+      c = f(a)
+      if c do
+        c
+      else
+        find_if(b, f)
+      end              
+    end
+  }
+
   def has? = cfn Bool "list_has" (List, Tag, Result)
 
   def join = fn {