hgweb: update _runwsgi try/except range to be valid
authorPierre-Yves David <pierre-yves.david@octobus.net>
Tue, 19 Dec 2023 21:38:46 +0100
changeset 51296 3972d090aba2
parent 51295 011eec5a66b2
child 51297 4d12ffde8377
hgweb: update _runwsgi try/except range to be valid The `tmpl` variable is used in the `except` and `finally`, so we need it created before the `try` is open.
mercurial/hgweb/hgwebdir_mod.py
--- a/mercurial/hgweb/hgwebdir_mod.py	Tue Dec 19 21:36:52 2023 +0100
+++ b/mercurial/hgweb/hgwebdir_mod.py	Tue Dec 19 21:38:46 2023 +0100
@@ -410,15 +410,15 @@
                     gc.collect(generation=1)
 
     def _runwsgi(self, req, res):
-        try:
-            self.refresh()
+        self.refresh()
 
-            csp, nonce = cspvalues(self.ui)
-            if csp:
-                res.headers[b'Content-Security-Policy'] = csp
+        csp, nonce = cspvalues(self.ui)
+        if csp:
+            res.headers[b'Content-Security-Policy'] = csp
 
-            virtual = req.dispatchpath.strip(b'/')
-            tmpl = self.templater(req, nonce)
+        virtual = req.dispatchpath.strip(b'/')
+        tmpl = self.templater(req, nonce)
+        try:
             ctype = tmpl.render(b'mimetype', {b'encoding': encoding.encoding})
 
             # Global defaults. These can be overridden by any handler.