[3.14] gh-70765: avoid waiting for HTTP headers when parsing HTTP/0.9 requests (GH-139514) (#139600)

(cherry picked from commit 13dc2fde8c)
(cherry picked from commit 1fe89d324e)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2025-10-08 12:39:59 +02:00 committed by GitHub
parent 297157d968
commit 32233d68d8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 51 additions and 0 deletions

View file

@ -324,6 +324,7 @@ def parse_request(self):
error response has already been sent back.
"""
is_http_0_9 = False
self.command = None # set in case of error on the first line
self.request_version = version = self.default_request_version
self.close_connection = True
@ -381,6 +382,7 @@ def parse_request(self):
HTTPStatus.BAD_REQUEST,
"Bad HTTP/0.9 request type (%r)" % command)
return False
is_http_0_9 = True
self.command, self.path = command, path
# gh-87389: The purpose of replacing '//' with '/' is to protect
@ -390,6 +392,11 @@ def parse_request(self):
if self.path.startswith('//'):
self.path = '/' + self.path.lstrip('/') # Reduce to a single /
# For HTTP/0.9, headers are not expected at all.
if is_http_0_9:
self.headers = {}
return True
# Examine the headers and look for a Connection directive.
try:
self.headers = http.client.parse_headers(self.rfile,