mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	Issue #15633: httplib.HTTPResponse is now mark closed when the server sends less than the advertised Content-Length.
This commit is contained in:
		
							parent
							
								
									6375257188
								
							
						
					
					
						commit
						beec61ae4e
					
				
					 3 changed files with 27 additions and 4 deletions
				
			
		|  | @ -199,6 +199,19 @@ def test_partial_reads_no_content_length(self): | |||
|         self.assertEqual(resp.read(1), b'') | ||||
|         self.assertTrue(resp.isclosed()) | ||||
| 
 | ||||
|     def test_partial_reads_incomplete_body(self): | ||||
|         # if the server shuts down the connection before the whole | ||||
|         # content-length is delivered, the socket is gracefully closed | ||||
|         body = "HTTP/1.1 200 Ok\r\nContent-Length: 10\r\n\r\nText" | ||||
|         sock = FakeSocket(body) | ||||
|         resp = client.HTTPResponse(sock) | ||||
|         resp.begin() | ||||
|         self.assertEqual(resp.read(2), b'Te') | ||||
|         self.assertFalse(resp.isclosed()) | ||||
|         self.assertEqual(resp.read(2), b'xt') | ||||
|         self.assertEqual(resp.read(1), b'') | ||||
|         self.assertTrue(resp.isclosed()) | ||||
| 
 | ||||
|     def test_host_port(self): | ||||
|         # Check invalid host_port | ||||
| 
 | ||||
|  | @ -349,7 +362,7 @@ def test_negative_content_length(self): | |||
|         resp = client.HTTPResponse(sock, method="GET") | ||||
|         resp.begin() | ||||
|         self.assertEqual(resp.read(), b'Hello\r\n') | ||||
|         resp.close() | ||||
|         self.assertTrue(resp.isclosed()) | ||||
| 
 | ||||
|     def test_incomplete_read(self): | ||||
|         sock = FakeSocket('HTTP/1.1 200 OK\r\nContent-Length: 10\r\n\r\nHello\r\n') | ||||
|  | @ -363,10 +376,9 @@ def test_incomplete_read(self): | |||
|                              "IncompleteRead(7 bytes read, 3 more expected)") | ||||
|             self.assertEqual(str(i), | ||||
|                              "IncompleteRead(7 bytes read, 3 more expected)") | ||||
|             self.assertTrue(resp.isclosed()) | ||||
|         else: | ||||
|             self.fail('IncompleteRead expected') | ||||
|         finally: | ||||
|             resp.close() | ||||
| 
 | ||||
|     def test_epipe(self): | ||||
|         sock = EPipeSocket( | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Antoine Pitrou
						Antoine Pitrou