diff options
author | bptato <nincsnevem662@gmail.com> | 2021-12-26 23:50:12 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2021-12-26 23:50:12 +0100 |
commit | 2b1dac71b2886ede9950f4ef91e7a0eb7b3e5ed5 (patch) | |
tree | 0971b3625f6cbc9d978ccb1a01bf7fde815dd94b /src/types | |
parent | 647089a99e3c44c4115274a8822ca0a4dd947d67 (diff) | |
download | chawan-2b1dac71b2886ede9950f4ef91e7a0eb7b3e5ed5.tar.gz |
Basic content type implementation
Diffstat (limited to 'src/types')
-rw-r--r-- | src/types/mime.nim | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/types/mime.nim b/src/types/mime.nim new file mode 100644 index 00000000..4dfe87e9 --- /dev/null +++ b/src/types/mime.nim @@ -0,0 +1,25 @@ +import tables + +const DefaultGuess = [ + ("html", "text/html"), + ("htm", "text/html"), + ("xhtml", "application/xhtml+xml"), + ("xhtm", "application/xhtml+xml"), + ("xht", "application/xhtml+xml"), +].toTable() + +proc guessContentType*(path: string): string = + var i = path.len - 1 + var n = 0 + while i > 0: + if path[i] == '/': + return "text/plain" + if path[i] == '.': + n = i + break + dec i + if n > 0: + let ext = path.substr(n + 1) + if ext in DefaultGuess: + return DefaultGuess[ext] + return "text/plain" |