AX_PYTHON_MODULE([kerberos], [fatal])
AX_PYTHON_MODULE([ldap], [fatal])
AX_PYTHON_MODULE([location], [fatal])
+AX_PYTHON_MODULE([magic], [fatal])
AX_PYTHON_MODULE([markdown], [fatal])
AX_PYTHON_MODULE([pakfire], [fatal])
AX_PYTHON_MODULE([pygments], [fatal])
import datetime
import functools
import logging
+import magic
import os
import shutil
import ssl
return s
+ # Initialize libmagic
+ magic = magic.Magic(mime=True, uncompress=False)
+
+ @run_in_thread
+ def mimetype(self, path):
+ # Make the path absolute
+ if not path.startswith("/"):
+ path = self.path(path)
+
+ return self.magic.from_file(path)
+
@run_in_thread
def makedirs(self, path, **kwargs):
"""
if not s:
raise tornado.web.HTTPError(404)
+ # Fetch the MIME type
+ mimetype = await self.backend.mimetype(path)
+
# Send a couple of headers
- self.set_header("Content-Type", "application/octet-stream")
+ self.set_header("Content-Type", mimetype or "application/octet-stream")
self.set_header("Content-Length", s.st_size)
self.set_header("Last-Modified", datetime.datetime.fromtimestamp(s.st_mtime))
self.set_header("Etag", "%x-%x" % (int(s.st_mtime), s.st_size))