diff options
author | bptato <nincsnevem662@gmail.com> | 2024-04-25 20:31:46 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-04-25 20:39:01 +0200 |
commit | a42f96ee6287c714ce90206009f20494995940db (patch) | |
tree | a7d76007e2360c84c0b309d8aa934c186851dbe6 /adapter/protocol | |
parent | 91707a9b2ee3ceee6bdd13f5262dcc1dd675fbc7 (diff) | |
download | chawan-a42f96ee6287c714ce90206009f20494995940db.tar.gz |
data: replace std/base64 with atob
std's version is known to be broken on versions we still support, and it makes no sense to use different decoders anyway. (This does introduce a bit of a dependency hell, because js/base64 depends on js/javascript which tries to bring in the entire QuickJS runtime. So we move that out into twtstr, and manually convert a Result[string, string] to DOMException in js/base64.)
Diffstat (limited to 'adapter/protocol')
-rw-r--r-- | adapter/protocol/data.nim | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/adapter/protocol/data.nim b/adapter/protocol/data.nim index e6c7318a..72263780 100644 --- a/adapter/protocol/data.nim +++ b/adapter/protocol/data.nim @@ -2,10 +2,10 @@ when NimMajor >= 2: import std/envvars else: import std/os -import std/base64 import std/strutils import loader/connecterror +import types/opt import utils/twtstr proc main() = @@ -18,12 +18,12 @@ proc main() = let sd = ct.len + 1 # data start let body = percentDecode(str, sd) if ct.endsWith(";base64"): - try: - let d = base64.decode(body) # decode from ct end + 1 + let d = atob0(body) # decode from ct end + 1 + if d.isSome: ct.setLen(ct.len - ";base64".len) # remove base64 indicator stdout.write("Content-Type: " & ct & "\n\n") - stdout.write(d) - except ValueError: + stdout.write(d.get) + else: stdout.write("Cha-Control: ConnectionError " & iu & " invalid data URL") else: stdout.write("Content-Type: " & ct & "\n\n") |