@@ -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