comparison mercurial/hgweb/request.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 9ed281bbf864
comparison
equal deleted inserted replaced
49845:e0c0545e2e55 49846:fda5a4b853ab
483 483
484 if ( 484 if (
485 self._bodybytes is None 485 self._bodybytes is None
486 and self._bodygen is None 486 and self._bodygen is None
487 and not self._bodywillwrite 487 and not self._bodywillwrite
488 and self._req.method != b'HEAD'
488 ): 489 ):
489 raise error.ProgrammingError(b'response body not defined') 490 raise error.ProgrammingError(b'response body not defined')
490 491
491 # RFC 7232 Section 4.1 states that a 304 MUST generate one of 492 # RFC 7232 Section 4.1 states that a 304 MUST generate one of
492 # {Cache-Control, Content-Location, Date, ETag, Expires, Vary} 493 # {Cache-Control, Content-Location, Date, ETag, Expires, Vary}
592 chunk = bytes(chunk) 593 chunk = bytes(chunk)
593 594
594 yield chunk 595 yield chunk
595 elif self._bodywillwrite: 596 elif self._bodywillwrite:
596 self._bodywritefn = write 597 self._bodywritefn = write
598 elif self._req.method == b'HEAD':
599 pass
597 else: 600 else:
598 error.ProgrammingError(b'do not know how to send body') 601 error.ProgrammingError(b'do not know how to send body')
599 602
600 def getbodyfile(self): 603 def getbodyfile(self):
601 """Obtain a file object like object representing the response body. 604 """Obtain a file object like object representing the response body.