about summary refs log tree commit diff stats
path: root/src/utils/twtstr.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-03-12 19:51:03 +0100
committerbptato <nincsnevem662@gmail.com>2024-03-12 20:20:24 +0100
commit22480a38c618aea42285b20868231f247932f2ab (patch)
treeba9b562124c1c30782ed87cd94122e962b80f637 /src/utils/twtstr.nim
parent232d861836993d81f7828a2917e8d242a23194e0 (diff)
downloadchawan-22480a38c618aea42285b20868231f247932f2ab.tar.gz
loader: remove applyHeaders
Better compute the values we need on-demand at the call sites; this way,
we can pass through content type attributes to mailcap too.

(Also, remove a bug where applyResponse was called twice.)
Diffstat (limited to 'src/utils/twtstr.nim')
-rw-r--r--src/utils/twtstr.nim21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim
index 4d6b48ea..fe6ba236 100644
--- a/src/utils/twtstr.nim
+++ b/src/utils/twtstr.nim
@@ -693,3 +693,24 @@ func strictParseEnum*[T: enum](s: string): Opt[T] =
     if s in tab:
       return ok(tab[s])
   return err()
+
+proc getContentTypeAttr*(contentType, attrname: string): string =
+  let kvs = contentType.after(';')
+  var i = kvs.find(attrname)
+  var s = ""
+  if i != -1 and kvs.len > i + attrname.len and
+      kvs[i + attrname.len] == '=':
+    i += attrname.len + 1
+    while i < kvs.len and kvs[i] in AsciiWhitespace:
+      inc i
+    var q = false
+    for j, c in kvs.toOpenArray(i, kvs.high):
+      if q:
+        s &= c
+      elif c == '\\':
+        q = true
+      elif c == ';' or c in AsciiWhitespace:
+        break
+      else:
+        s &= c
+  return s