]> git.ipfire.org Git - pbs.git/commitdiff
mirrors: Send the correct MIME type
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 11 Feb 2025 16:29:48 +0000 (16:29 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 11 Feb 2025 16:29:48 +0000 (16:29 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
configure.ac
src/buildservice/__init__.py
src/web/mirrors.py

index 41c8e636cefab96a00820d647e13b5b5e10cf644..0171bdab54b3c0068cfc5b65db1898294f540ef0 100644 (file)
@@ -93,6 +93,7 @@ AX_PYTHON_MODULE([jinja2], [fatal])
 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])
index 24bc179d103d4509b8d460e3dba6a42316b62f35..bcff0b0cf30e246e3fe6811350b2851e66b3accb 100644 (file)
@@ -6,6 +6,7 @@ import configparser
 import datetime
 import functools
 import logging
+import magic
 import os
 import shutil
 import ssl
@@ -384,6 +385,17 @@ class Backend(object):
 
                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):
                """
index b3d020b111dbfd165fadb620c9294bc99d248766..cb305bf0b2bd743a24e353bb4adbce48fd1b55e8 100644 (file)
@@ -182,8 +182,11 @@ class DownloadsHandler(base.BaseHandler):
                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))