From e1f73697ff7cabd55db4e63b6b77099222f1cb4c Mon Sep 17 00:00:00 2001 From: shortcutme Date: Mon, 28 Oct 2019 16:11:45 +0100 Subject: [PATCH] Extend built-in content types list --- src/Ui/UiRequest.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/Ui/UiRequest.py b/src/Ui/UiRequest.py index fa3719e5..40dd7f89 100644 --- a/src/Ui/UiRequest.py +++ b/src/Ui/UiRequest.py @@ -26,6 +26,19 @@ status_texts = { 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): pass @@ -192,14 +205,10 @@ class UiRequest(object): file_name = file_name.lower() ext = file_name.rsplit(".", 1)[-1] - if ext == "css": # Force correct css content type - content_type = "text/css" - elif ext == "js": # Force correct javascript content type - content_type = "text/javascript" - elif ext == "json": # Correct json header - content_type = "application/json" - elif ext in ("ttf", "woff", "otf", "woff2", "eot"): - content_type = "application/font" + if ext in content_types: + content_type = content_types[ext] + elif ext in ("ttf", "woff", "otf", "woff2", "eot", "sfnt", "collection"): + content_type = "font/%s" % ext else: content_type = mimetypes.guess_type(file_name)[0]