hgweb: ignore web.templates config when guessing mime type for static content
authorMartin von Zweigbergk <martinvonz@google.com>
Mon, 03 Aug 2020 23:38:50 -0700
changeset 45379 ec2fc4d038c2
parent 45378 dc9fe90bdbd5
child 45380 f0735f2ce542
hgweb: ignore web.templates config when guessing mime type for static content Frozen binaries won't have a file-system path for static content, so I'd like to remove dependence on that. From the documentation, it seems like `mimetypes.guess_type()` only cares about the suffix, so I think it should be enough to pass in just path under the `web.templates` directory. Differential Revision: https://phab.mercurial-scm.org/D8935
mercurial/hgweb/common.py
--- a/mercurial/hgweb/common.py	Sat Aug 22 16:03:44 2020 -0700
+++ b/mercurial/hgweb/common.py	Mon Aug 03 23:38:50 2020 -0700
@@ -201,7 +201,7 @@
     try:
         os.stat(path)
         ct = pycompat.sysbytes(
-            mimetypes.guess_type(pycompat.fsdecode(path))[0] or r"text/plain"
+            mimetypes.guess_type(pycompat.fsdecode(fpath))[0] or r"text/plain"
         )
         with open(path, b'rb') as fh:
             data = fh.read()