Add some fixed content_type
This commit is contained in:
parent
1b307166ee
commit
40b84755de
1 changed files with 10 additions and 8 deletions
|
@ -174,21 +174,23 @@ class UiRequest(object):
|
||||||
# Get mime by filename
|
# Get mime by filename
|
||||||
def getContentType(self, file_name):
|
def getContentType(self, file_name):
|
||||||
file_name = file_name.lower()
|
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]
|
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:
|
if not content_type:
|
||||||
content_type = "application/octet-stream"
|
content_type = "application/octet-stream"
|
||||||
|
|
||||||
return content_type
|
return content_type.lower()
|
||||||
|
|
||||||
# Return: <dict> Posted variables
|
# Return: <dict> Posted variables
|
||||||
def getPosted(self):
|
def getPosted(self):
|
||||||
|
|
Loading…
Reference in a new issue