Add some fixed content_type

This commit is contained in:
shortcutme 2019-07-01 16:28:37 +02:00
parent 1b307166ee
commit 40b84755de
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE

View file

@ -174,21 +174,23 @@ class UiRequest(object):
# Get mime by filename
def getContentType(self, file_name):
file_name = file_name.lower()
ext = file_name.split(".", 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"
else:
content_type = mimetypes.guess_type(file_name)[0]
if content_type:
content_type = content_type.lower()
if file_name.endswith(".css"): # Force correct css content type
content_type = "text/css"
if file_name.endswith(".js"): # Force correct javascript content type
content_type = "text/javascript"
if file_name.endswith(".json"): # Correct json header
content_type = "application/json"
if not content_type:
content_type = "application/octet-stream"
return content_type
return content_type.lower()
# Return: <dict> Posted variables
def getPosted(self):