about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-10-01 21:23:33 +0200
committerbptato <nincsnevem662@gmail.com>2024-10-01 21:27:21 +0200
commitef1a514a4d5a338831bf8828bb6f0e2f8addda2a (patch)
treeba09f6b5e2707abf7c2b71c5ca8367a1897923b8
parentb0a511f900a2884c0d1bb55e3991c068ef3e37f2 (diff)
downloadchawan-ef1a514a4d5a338831bf8828bb6f0e2f8addda2a.tar.gz
http: remove twtstr dependency
-rw-r--r--Makefile16
-rw-r--r--adapter/protocol/http.nim14
2 files changed, 18 insertions, 12 deletions
diff --git a/Makefile b/Makefile
index 88670d04..b6db04cb 100644
--- a/Makefile
+++ b/Makefile
@@ -91,18 +91,18 @@ $(OUTDIR_CGI_BIN)/gmifetch: adapter/protocol/gmifetch.c
 	@mkdir -p "$(OUTDIR_CGI_BIN)"
 	$(CC) $(GMIFETCH_CFLAGS) adapter/protocol/gmifetch.c -o "$(OUTDIR_CGI_BIN)/gmifetch" $(GMIFETCH_LDFLAGS)
 
-twtstr = src/utils/twtstr.nim src/utils/charcategory.nim src/utils/map.nim src/utils/twtuni.nim
+twtstr = src/utils/twtstr.nim src/utils/charcategory.nim src/utils/map.nim \
+	src/utils/twtuni.nim src/types/opt.nim
 dynstream = src/io/dynstream.nim src/io/serversocket.nim
 lcgi = $(dynstream) $(twtstr) adapter/protocol/lcgi.nim
+curl = adapter/protocol/curl.nim adapter/protocol/curlerrors.nim
 $(OUTDIR_CGI_BIN)/man: lib/monoucha/monoucha/jsregex.nim \
-		lib/monoucha/monoucha/libregexp.nim src/types/opt.nim $(twtstr)
-$(OUTDIR_CGI_BIN)/http: adapter/protocol/curlwrap.nim \
-		adapter/protocol/curlerrors.nim adapter/protocol/curl.nim \
-		src/utils/sandbox.nim $(twtstr)
+		lib/monoucha/monoucha/libregexp.nim $(twtstr)
+$(OUTDIR_CGI_BIN)/http: $(curl) src/utils/sandbox.nim
 $(OUTDIR_CGI_BIN)/about: res/chawan.html res/license.md
-$(OUTDIR_CGI_BIN)/file: adapter/protocol/dirlist.nim $(twtstr) src/utils/strwidth.nim
-$(OUTDIR_CGI_BIN)/ftp: adapter/protocol/dirlist.nim $(twtstr) src/utils/strwidth.nim \
-		src/types/opt.nim adapter/protocol/curl.nim
+$(OUTDIR_CGI_BIN)/file: $(twtstr) adapter/protocol/dirlist.nim src/utils/strwidth.nim
+$(OUTDIR_CGI_BIN)/ftp: $(lcgi) adapter/protocol/dirlist.nim src/utils/strwidth.nim
+$(OUTDIR_CGI_BIN)/sftp: $(curl) $(twtstr) src/utils/strwidth.nim adapter/protocol/dirlist.nim
 $(OUTDIR_CGI_BIN)/gopher: adapter/gophertypes.nim $(lcgi)
 $(OUTDIR_CGI_BIN)/stbi: adapter/img/stbi.nim adapter/img/stb_image.c \
 		adapter/img/stb_image.h src/utils/sandbox.nim $(dynstream)
diff --git a/adapter/protocol/http.nim b/adapter/protocol/http.nim
index 69542288..4a12e898 100644
--- a/adapter/protocol/http.nim
+++ b/adapter/protocol/http.nim
@@ -10,8 +10,6 @@ import curl
 import curlerrors
 import curlwrap
 
-import utils/twtstr
-
 type
   EarlyHintState = enum
     ehsNone, ehsStarted, ehsDone
@@ -90,6 +88,13 @@ proc curlPreRequest(clientp: pointer; conn_primary_ip, conn_local_ip: cstring;
   enterNetworkSandbox()
   return 0 # ok
 
+func startsWithIgnoreCase(s1, s2: openArray[char]): bool =
+  if s1.len < s2.len: return false
+  for i in 0 ..< s2.len:
+    if s1[i].toLowerAscii() != s2[i].toLowerAscii():
+      return false
+  return true
+
 proc main() =
   let curl = curl_easy_init()
   doAssert curl != nil
@@ -147,8 +152,9 @@ proc main() =
   else: discard #TODO
   let headers = getEnv("REQUEST_HEADERS")
   for line in headers.split("\r\n"):
-    if line.startsWithIgnoreCase("Accept-Encoding: "):
-      let s = line.after(' ')
+    const needle = "Accept-Encoding: "
+    if line.startsWithIgnoreCase(needle):
+      let s = line.substr(needle.len)
       # From the CURLOPT_ACCEPT_ENCODING manpage:
       # > The application does not have to keep the string around after
       # > setting this option.