diff mercurial/hgweb/server.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 48f1b314056b
children
line wrap: on
line diff
--- a/mercurial/hgweb/server.py	Wed Jan 04 16:02:22 2023 +0100
+++ b/mercurial/hgweb/server.py	Fri Dec 16 17:46:20 2022 +0100
@@ -151,6 +151,9 @@
     def do_GET(self):
         self.do_POST()
 
+    def do_HEAD(self):
+        self.do_POST()
+
     def do_hgweb(self):
         self.sent_headers = False
         path, query = _splitURI(self.path)
@@ -246,7 +249,11 @@
             self.send_header(*h)
             if h[0].lower() == 'content-length':
                 self.length = int(h[1])
-        if self.length is None and saved_status[0] != common.HTTP_NOT_MODIFIED:
+        if (
+            self.length is None
+            and saved_status[0] != common.HTTP_NOT_MODIFIED
+            and self.command != 'HEAD'
+        ):
             self._chunked = (
                 not self.close_connection and self.request_version == 'HTTP/1.1'
             )