fix: serve WebP with a portable MIME type
This commit is contained in:
1 parent
d182cd30fa
commit
30d012de80
5 files changed
+23
-1
No files matched your search
+6
-1
@@ -585,8 +585,13 @@ class Handler(BaseHTTPRequestHandler):
|
||||
def _file(self, path: Path) -> None:
|
||||
"""Отдаёт существующий статический файл с подходящим MIME-типом."""
|
||||
content = path.read_bytes()
|
||||
# Python slim images may lack the system MIME database for WebP.
|
||||
content_type = (
|
||||
"image/webp" if path.suffix.lower() == ".webp"
|
||||
else mimetypes.guess_type(path.name)[0] or "application/octet-stream"
|
||||
)
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", mimetypes.guess_type(path.name)[0] or "application/octet-stream")
|
||||
self.send_header("Content-Type", content_type)
|
||||
self.send_header("Content-Length", str(len(content)))
|
||||
self.end_headers()
|
||||
self.wfile.write(content)
|
||||
|
||||
Reference in new issue
Block a user