diff mercurial/hgweb/hgweb_mod.py @ 49846:fda5a4b853ab

hgweb: skip body creation of HEAD for most requests The body is thrown away anyway, so this just wastes a lot of CPU time. In the case of /archive/, this skips manifest processing and the actual file archiving, resulting in a huge difference. The most tricky part here is skipping the Content-Length creation as it would indicate the output size for the corresponding GET request.
author Joerg Sonnenberger <joerg@bec.de>
date Fri, 16 Dec 2022 17:46:20 +0100
parents 642e31cb55f0
children 4077d6222cf1
line wrap: on
line diff
--- a/mercurial/hgweb/hgweb_mod.py	Wed Jan 04 16:02:22 2023 +0100
+++ b/mercurial/hgweb/hgweb_mod.py	Fri Dec 16 17:46:20 2022 +0100
@@ -230,8 +230,9 @@
 
     def sendtemplate(self, name, **kwargs):
         """Helper function to send a response generated from a template."""
-        kwargs = pycompat.byteskwargs(kwargs)
-        self.res.setbodygen(self.tmpl.generate(name, kwargs))
+        if self.req.method != b'HEAD':
+            kwargs = pycompat.byteskwargs(kwargs)
+            self.res.setbodygen(self.tmpl.generate(name, kwargs))
         return self.res.sendresponse()