diff --git a/src/urllib3/connection.py b/src/urllib3/connection.py index 0318601bbd..3a42734120 100644 --- a/src/urllib3/connection.py +++ b/src/urllib3/connection.py @@ -272,6 +272,13 @@ def proxy_is_forwarding(self) -> bool: """ return bool(self.proxy) and self._tunnel_host is None + @property + def proxy_is_tunneling(self) -> bool: + """ + Return True if a tunneling proxy is configured, else return False + """ + return self._tunnel_host is not None + def close(self) -> None: try: super().close() @@ -618,7 +625,7 @@ def connect(self) -> None: tls_in_tls = False # Do we need to establish a tunnel? - if self._tunnel_host is not None: + if self.proxy_is_tunneling: # We're tunneling to an HTTPS origin so need to do TLS-in-TLS. if self._tunnel_scheme == "https": # _connect_tls_proxy will verify and assign proxy_is_verified @@ -632,7 +639,7 @@ def connect(self) -> None: self._tunnel() # type: ignore[attr-defined] # Override the host with the one we're requesting data from. - server_hostname = self._tunnel_host + server_hostname = self._tunnel_host # type: ignore[assignment] if self.server_hostname is not None: server_hostname = self.server_hostname