contenttypes.nim
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
import json, strutils, strtabs
proc loadContentTypes(): StringTableRef =
result = newStringTable(modeCaseInsensitive)
const raw_json = "contenttypes.json".slurp
let json = raw_json.parseJson
for item in json.items:
for pair in item.pairs:
result[$pair.key] = $pair.val
let CONTENT_TYPES* = loadContentTypes()
proc isBinary*(ct: string): bool =
if ct.endsWith "xml":
return false
elif ct.endsWith "html":
return false
elif ct.endsWith "json":
return false
elif ct.endsWith "script":
return false
elif ct.endsWith "sql":
return false
elif ct.startsWith "audio/":
return true
elif ct.startsWith "image/":
return true
elif ct.startsWith "message/":
return true
elif ct.startsWith "model/":
return true
elif ct.startsWith "multipart/":
return true
elif ct.startsWith "text/":
return false
elif ct.startsWith "video/":
return true
else:
return true
proc isTextual*(ct: string): bool =
return not ct.isBinary
|