https://github.com/python/cpython/commit/755e3239cca1386c93dd55fb54c07c74dac1c85d
commit: 755e3239cca1386c93dd55fb54c07c74dac1c85d
branch: main
author: tonghuaroot (童话) <[email protected]>
committer: orsenthil <[email protected]>
date: 2026-11-12T07:58:35-08:00
summary:
gh-161861: preserve http continue timeout after rejected request (#161862)
move the continue timeout assignment after the connection state check so a
rejected putrequest call cannot modify the active request.
files:
A Misc/NEWS.d/next/Library/2026-11-12-17-53-13.gh-issue-161861.Kf7Qm2.rst
M Lib/http/client.py
M Lib/test/test_httplib.py
diff --git a/Lib/http/client.py b/Lib/http/client.py
index 4bdb8f72f979b1..aa643e7f63ddd8 100644
--- a/Lib/http/client.py
+++ b/Lib/http/client.py
@@ -1268,7 +1268,6 @@ def putrequest(self, method, url, skip_host=False,
"""
if continue_timeout <= 0.0:
raise ValueError("continue_timeout must be greater than 0")
- self._continue_timeout = continue_timeout
# if a prior response has been completed, then forget about it.
if self.__response and self.__response.isclosed():
@@ -1294,6 +1293,7 @@ def putrequest(self, method, url, skip_host=False,
#
if self.__state == _CS_IDLE:
self.__state = _CS_REQ_STARTED
+ self._continue_timeout = continue_timeout
else:
raise CannotSendRequest(self.__state)
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py
index 849c44e17aab0a..adcd11e22d3337 100644
--- a/Lib/test/test_httplib.py
+++ b/Lib/test/test_httplib.py
@@ -2587,6 +2587,20 @@ def test_putrequest_continue_timeout(self):
self.assertIn(b'Body content', conn.sock.data)
self.assertEqual(conn.getresponse().code, 200)
+ def test_failed_putrequest_preserves_continue_timeout(self):
+ conn = FakeSocketHTTPConnection(
+ b'HTTP/1.1 100 Continue\r\n'
+ b'\r\n'
+ )
+ conn._select = mock.Mock(wraps=conn.fake_select)
+ conn.putrequest('PUT', '/', continue_timeout=0.25)
+ with self.assertRaises(client.CannotSendRequest):
+ conn.putrequest('GET', '/', continue_timeout=10)
+ conn.putheader('Expect', '100-continue')
+ conn.putheader('Content-Length', '12')
+ conn.endheaders(b'Body content')
+ conn._select.assert_called_once_with([conn.sock], [], [], 0.25)
+
def test_invalid_continue_timeout(self):
conn = FakeSocketHTTPConnection(b'')
for timeout in (0, -1):
diff --git
a/Misc/NEWS.d/next/Library/2026-11-12-17-53-13.gh-issue-161861.Kf7Qm2.rst
b/Misc/NEWS.d/next/Library/2026-11-12-17-53-13.gh-issue-161861.Kf7Qm2.rst
new file mode 100644
index 00000000000000..febea87b27d5a1
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2026-11-12-17-53-13.gh-issue-161861.Kf7Qm2.rst
@@ -0,0 +1,2 @@
+Preserve the active request's ``continue_timeout`` when a second
+:meth:`~http.client.HTTPConnection.putrequest` call is rejected.
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]