Override MIME for some types that are actually text

This commit is contained in:
Kovid Goyal 2020-10-25 15:11:44 +05:30
parent 30b8991a73
commit 3960c6678d
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -19,6 +19,9 @@ known_extensions = {
}
text_mimes = ('application/javascript', 'application/x-sh', 'application/json')
def is_rc_file(path: str) -> bool:
name = os.path.basename(path)
return '.' not in name and name.endswith('rc')
@ -45,6 +48,8 @@ def guess_type(path: str) -> Optional[str]:
if not mt:
ext = path.rpartition('.')[-1].lower()
mt = known_extensions.get(ext)
if mt in text_mimes:
mt = 'text/' + mt.split('/', 1)[-1]
if not mt and is_rc_file(path):
mt = 'text/plain'
return mt