diff options
author | bptato <nincsnevem662@gmail.com> | 2023-12-12 19:57:24 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-12-12 19:57:24 +0100 |
commit | 189e73f7092a69699f3a6ca39aa105d318baedd4 (patch) | |
tree | f363bc19211b30ee061a22c0c81bb03bb38558f4 /adapter | |
parent | 820f0f0f039252533133c3bd1037a73036815a45 (diff) | |
download | chawan-189e73f7092a69699f3a6ca39aa105d318baedd4.tar.gz |
local CGI improvements, move data: to cgi-bin
error codes are WIP, not final yet...
Diffstat (limited to 'adapter')
-rw-r--r-- | adapter/data/data.nim | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/adapter/data/data.nim b/adapter/data/data.nim new file mode 100644 index 00000000..7b022976 --- /dev/null +++ b/adapter/data/data.nim @@ -0,0 +1,29 @@ +import std/envvars +import std/base64 +import std/strutils + +import utils/twtstr + +proc main() = + let str = getEnv("MAPPED_URI_PATH") + const si = "data:".len # start index + var ct = str.until(',', si) + for c in ct: + if c notin AsciiAlphaNumeric and c != '/': + stdout.write("Cha-Control: ConnectionError -7 invalid data URL") + return + let sd = si + 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 + ct.setLen(ct.len - ";base64".len) # remove base64 indicator + stdout.write("Content-Type: " & ct & "\n\n") + stdout.write(d) + except ValueError: + stdout.write("Cha-Control: ConnectionError -7 invalid data URL") + else: + stdout.write("Content-Type: " & ct & "\n\n") + stdout.write(body) + +main() |