Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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)

Expand Down
14 changes: 14 additions & 0 deletions Lib/test/test_httplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Preserve the active request's ``continue_timeout`` when a second
:meth:`~http.client.HTTPConnection.putrequest` call is rejected.
Loading