Use itemtypes to figure out the mime type in HTTP mode

This commit is contained in:
Juhani Krekelä 2021-09-10 17:58:48 +03:00
parent 53a0ef3daf
commit 0867a6ef40
1 changed files with 5 additions and 1 deletions

View File

@ -411,6 +411,7 @@ def read_infofile(file_path):
# TODO: Read from file
extension_mimetypes = {'.txt': 'text/plain', '.text': 'text/plain', '.log': 'text/plain', '.html': 'text/html'}
itemtype_mimetypes = {'0': 'text/plain', '1': 'text/x-gophermap', 'h': 'text/html'}
mimetype_cache = {}
mimetype_cache_lock = threading.Lock()
@ -726,7 +727,10 @@ class Serve(threading.Thread):
try:
full_path = get_full_path(path, config = self.config)
mimetype = get_mimetype(full_path, config = self.config)
if protocol == Protocol.http and itemtype in itemtype_mimetypes:
mimetype = itemtype_mimetypes[itemtype]
else:
mimetype = get_mimetype(full_path, config = self.config)
file = get_file(full_path, config = self.config)
except FileNotFoundError: