浏览代码

improve guess_mime_using_file

pull/8/head
lilydjwg 5 年前
父节点
当前提交
90c3293803
共有 1 个文件被更改,包括 5 次插入1 次删除
  1. +5
    -1
      main.py

+ 5
- 1
main.py 查看文件

@ -34,12 +34,16 @@ def guess_mime_using_file(path):
mime = mime.rstrip(';')
encoding = encoding.split('=')[-1]
# older file doesn't know webp
if mime == 'application/octet-stream':
result = subprocess.check_output(['file', path]).decode()
_, desc = result.split(None, 1)
if 'Web/P image' in desc:
return 'image/webp', 'binary'
return 'image/webp', None
# Tornado will treat non-gzip encoding as application/octet-stream
if encoding != 'gzip':
encoding = None
return mime, encoding
mimetypes.guess_type = guess_mime_using_file


正在加载...
取消
保存