diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py index 9fa6ecf9c08e27..397895d7c4be8a 100644 --- a/Lib/test/test_httpservers.py +++ b/Lib/test/test_httpservers.py @@ -320,7 +320,10 @@ class request_handler(BaseHTTPRequestHandler): default_request_version = 'HTTP/1.1' def do_GET(self): + # gh-69282: Tell the client we're not sending any content along + # with the response code. self.send_response(HTTPStatus.OK) + self.send_header('Content-Length', 0) self.end_headers() def do_ERROR(self): @@ -331,8 +334,15 @@ def test_get(self): self.con.connect() with support.captured_stderr() as err: - self.con.request('GET', '/') + # gh-69282: HTTP/1.1 specifies that the socket connection is to + # remain open, this, on certain systems, causes Python to deadlock + # waiting for the socket to close. + # To combat this, we send the test server the "Connection" header + # with "close" for the value forcing the server and client to + # terminate the socket allowing the test to resume. + self.con.request('GET', '/', headers={'Connection': 'close'}) self.con.getresponse() + self.con.close() self.assertTrue( err.getvalue().endswith('"GET / HTTP/1.1" 200 -\n'))