Skip to content

Commit 1f3b3dd

Browse files
committed
100 continue fix
1 parent 78ae246 commit 1f3b3dd

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

awscli/botocore/awsrequest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def _is_100_continue_status(self, maybe_status_line):
221221
parts = maybe_status_line.split(None, 2)
222222
# Check for HTTP/<version> 100 Continue\r\n
223223
return (
224-
len(parts) >= 3
224+
len(parts) >= 2
225225
and parts[0].startswith(b'HTTP/')
226226
and parts[1] == b'100'
227227
)

tests/unit/botocore/test_awsrequest.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,33 @@ def test_expect_100_sends_connection_header(self):
399399
response = conn.getresponse()
400400
self.assertEqual(response.status, 500)
401401

402+
def test_expect_100_sends_connection_header_optional_continue(self):
403+
# When using squid as an HTTP proxy, it will also send
404+
# a Connection: keep-alive header back with the 100 continue
405+
# response. We need to ensure we handle this case.
406+
with mock.patch('urllib3.util.wait_for_read') as wait_mock:
407+
# Shows the server first sending a 100 continue response
408+
# then a 500 response. We're picking 500 to confirm we
409+
# actually parse the response instead of getting the
410+
# default status of 200 which happens when we can't parse
411+
# the response.
412+
s = FakeSocket(
413+
b'HTTP/1.1 100\r\n' # HTTP/<version> 100\r\n - excluding reason "Continue"
414+
b'Connection: keep-alive\r\n'
415+
b'\r\n'
416+
b'HTTP/1.1 500 Internal Service Error\r\n'
417+
)
418+
conn = AWSHTTPConnection('s3.amazonaws.com', 443)
419+
conn.sock = s
420+
wait_mock.return_value = True
421+
conn.request(
422+
'GET', '/bucket/foo', b'body', {'Expect': b'100-continue'}
423+
)
424+
# Assert that we waited for the 100-continue response
425+
self.assertEqual(wait_mock.call_count, 1)
426+
response = conn.getresponse()
427+
self.assertEqual(response.status, 500)
428+
402429
def test_expect_100_continue_sends_307(self):
403430
# This is the case where we send a 100 continue and the server
404431
# immediately sends a 307

0 commit comments

Comments
 (0)