mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 21:51:50 +00:00 
			
		
		
		
	Issue #22095: Fixed HTTPConnection.set_tunnel with default port. The port
value in the host header was set to "None". Patch by Demian Brecht.
This commit is contained in:
		
							parent
							
								
									1e40f10886
								
							
						
					
					
						commit
						4ac7ed97a8
					
				
					 3 changed files with 11 additions and 8 deletions
				
			
		|  | @ -771,8 +771,7 @@ def set_tunnel(self, host, port=None, headers=None): | |||
|         if self.sock: | ||||
|             raise RuntimeError("Can't set up tunnel for established connection") | ||||
| 
 | ||||
|         self._tunnel_host = host | ||||
|         self._tunnel_port = port | ||||
|         self._tunnel_host, self._tunnel_port = self._get_hostport(host, port) | ||||
|         if headers: | ||||
|             self._tunnel_headers = headers | ||||
|         else: | ||||
|  | @ -802,9 +801,8 @@ def set_debuglevel(self, level): | |||
|         self.debuglevel = level | ||||
| 
 | ||||
|     def _tunnel(self): | ||||
|         (host, port) = self._get_hostport(self._tunnel_host, | ||||
|                                           self._tunnel_port) | ||||
|         connect_str = "CONNECT %s:%d HTTP/1.0\r\n" % (host, port) | ||||
|         connect_str = "CONNECT %s:%d HTTP/1.0\r\n" % (self._tunnel_host, | ||||
|             self._tunnel_port) | ||||
|         connect_bytes = connect_str.encode("ascii") | ||||
|         self.send(connect_bytes) | ||||
|         for header, value in self._tunnel_headers.items(): | ||||
|  |  | |||
|  | @ -1068,11 +1068,13 @@ def create_connection(address, timeout=None, source_address=None): | |||
| 
 | ||||
|         self.assertEqual(conn.sock.host, 'proxy.com') | ||||
|         self.assertEqual(conn.sock.port, 80) | ||||
|         self.assertTrue(b'CONNECT destination.com' in conn.sock.data) | ||||
|         self.assertTrue(b'Host: destination.com' in conn.sock.data) | ||||
|         self.assertIn(b'CONNECT destination.com', conn.sock.data) | ||||
|         # issue22095 | ||||
|         self.assertNotIn(b'Host: destination.com:None', conn.sock.data) | ||||
|         self.assertIn(b'Host: destination.com', conn.sock.data) | ||||
| 
 | ||||
|         # This test should be removed when CONNECT gets the HTTP/1.1 blessing | ||||
|         self.assertTrue(b'Host: proxy.com' not in conn.sock.data) | ||||
|         self.assertNotIn(b'Host: proxy.com', conn.sock.data) | ||||
| 
 | ||||
|         conn.close() | ||||
|         conn.request('PUT', '/', '') | ||||
|  |  | |||
|  | @ -39,6 +39,9 @@ Core and Builtins | |||
| Library | ||||
| ------- | ||||
| 
 | ||||
| - Issue #22095: Fixed HTTPConnection.set_tunnel with default port.  The port | ||||
|   value in the host header was set to "None".  Patch by Demian Brecht. | ||||
| 
 | ||||
| - Issue #23016: A warning no longer produces an AttributeError when the program | ||||
|   is run with pythonw.exe. | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Serhiy Storchaka
						Serhiy Storchaka