about summary refs log tree commit diff stats
path: root/adapter/protocol
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 /adapter/protocol
parentb0a511f900a2884c0d1bb55e3991c068ef3e37f2 (diff)
downloadchawan-ef1a514a4d5a338831bf8828bb6f0e2f8addda2a.tar.gz
http: remove twtstr dependency
Diffstat (limited to 'adapter/protocol')
-rw-r--r--adapter/protocol/http.nim14
1 files changed, 10 insertions, 4 deletions
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.