mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
[3.14] gh-70765: avoid waiting for HTTP headers when parsing HTTP/0.9 requests (GH-139514) (#139600)
(cherry picked from commit13dc2fde8c) (cherry picked from commit1fe89d324e) Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
This commit is contained in:
parent
297157d968
commit
32233d68d8
3 changed files with 51 additions and 0 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue