Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/urllib3/util/proxy.py: 38%
13 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-08 06:40 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-08 06:40 +0000
1from __future__ import annotations
3import typing
5from .url import Url
7if typing.TYPE_CHECKING:
8 from ..connection import ProxyConfig
11def connection_requires_http_tunnel(
12 proxy_url: Url | None = None,
13 proxy_config: ProxyConfig | None = None,
14 destination_scheme: str | None = None,
15) -> bool:
16 """
17 Returns True if the connection requires an HTTP CONNECT through the proxy.
19 :param URL proxy_url:
20 URL of the proxy.
21 :param ProxyConfig proxy_config:
22 Proxy configuration from poolmanager.py
23 :param str destination_scheme:
24 The scheme of the destination. (i.e https, http, etc)
25 """
26 # If we're not using a proxy, no way to use a tunnel.
27 if proxy_url is None:
28 return False
30 # HTTP destinations never require tunneling, we always forward.
31 if destination_scheme == "http":
32 return False
34 # Support for forwarding with HTTPS proxies and HTTPS destinations.
35 if (
36 proxy_url.scheme == "https"
37 and proxy_config
38 and proxy_config.use_forwarding_for_https
39 ):
40 return False
42 # Otherwise always use a tunnel.
43 return True