jpayne@7: from __future__ import annotations jpayne@7: jpayne@7: import typing jpayne@7: jpayne@7: from .url import Url jpayne@7: jpayne@7: if typing.TYPE_CHECKING: jpayne@7: from ..connection import ProxyConfig jpayne@7: jpayne@7: jpayne@7: def connection_requires_http_tunnel( jpayne@7: proxy_url: Url | None = None, jpayne@7: proxy_config: ProxyConfig | None = None, jpayne@7: destination_scheme: str | None = None, jpayne@7: ) -> bool: jpayne@7: """ jpayne@7: Returns True if the connection requires an HTTP CONNECT through the proxy. jpayne@7: jpayne@7: :param URL proxy_url: jpayne@7: URL of the proxy. jpayne@7: :param ProxyConfig proxy_config: jpayne@7: Proxy configuration from poolmanager.py jpayne@7: :param str destination_scheme: jpayne@7: The scheme of the destination. (i.e https, http, etc) jpayne@7: """ jpayne@7: # If we're not using a proxy, no way to use a tunnel. jpayne@7: if proxy_url is None: jpayne@7: return False jpayne@7: jpayne@7: # HTTP destinations never require tunneling, we always forward. jpayne@7: if destination_scheme == "http": jpayne@7: return False jpayne@7: jpayne@7: # Support for forwarding with HTTPS proxies and HTTPS destinations. jpayne@7: if ( jpayne@7: proxy_url.scheme == "https" jpayne@7: and proxy_config jpayne@7: and proxy_config.use_forwarding_for_https jpayne@7: ): jpayne@7: return False jpayne@7: jpayne@7: # Otherwise always use a tunnel. jpayne@7: return True