| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
import typing |
| 4 |
|
| 5 |
from .url import Url |
| 6 |
|
| 7 |
if typing.TYPE_CHECKING: |
| 8 |
from ..connection import ProxyConfig |
| 9 |
|
| 10 |
|
| 11 |
def 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. |
| 18 |
|
| 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 |
| 29 |
|
| 30 |
# HTTP destinations never require tunneling, we always forward. |
| 31 |
if destination_scheme == "http": |
| 32 |
return False |
| 33 |
|
| 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 |
| 41 |
|
| 42 |
# Otherwise always use a tunnel. |
| 43 |
return True |