Extend built-in content types list
This commit is contained in:
parent
e82155aac4
commit
e1f73697ff
1 changed files with 17 additions and 8 deletions
|
@ -26,6 +26,19 @@ status_texts = {
|
||||||
500: "500 Internal Server Error",
|
500: "500 Internal Server Error",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
content_types = {
|
||||||
|
"asc": "application/pgp-keys",
|
||||||
|
"css": "text/css",
|
||||||
|
"gpg": "application/pgp-encrypted",
|
||||||
|
"html": "text/html",
|
||||||
|
"js": "application/javascript",
|
||||||
|
"json": "application/json",
|
||||||
|
"sig": "application/pgp-signature",
|
||||||
|
"txt": "text/plain",
|
||||||
|
"webmanifest": "application/manifest+json",
|
||||||
|
"webp": "image/webp"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class SecurityError(Exception):
|
class SecurityError(Exception):
|
||||||
pass
|
pass
|
||||||
|
@ -192,14 +205,10 @@ class UiRequest(object):
|
||||||
file_name = file_name.lower()
|
file_name = file_name.lower()
|
||||||
ext = file_name.rsplit(".", 1)[-1]
|
ext = file_name.rsplit(".", 1)[-1]
|
||||||
|
|
||||||
if ext == "css": # Force correct css content type
|
if ext in content_types:
|
||||||
content_type = "text/css"
|
content_type = content_types[ext]
|
||||||
elif ext == "js": # Force correct javascript content type
|
elif ext in ("ttf", "woff", "otf", "woff2", "eot", "sfnt", "collection"):
|
||||||
content_type = "text/javascript"
|
content_type = "font/%s" % ext
|
||||||
elif ext == "json": # Correct json header
|
|
||||||
content_type = "application/json"
|
|
||||||
elif ext in ("ttf", "woff", "otf", "woff2", "eot"):
|
|
||||||
content_type = "application/font"
|
|
||||||
else:
|
else:
|
||||||
content_type = mimetypes.guess_type(file_name)[0]
|
content_type = mimetypes.guess_type(file_name)[0]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue