Add URLLib3ProxyTransport
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Tom Christie · committed by Tom Christie · parent 9f58afd · Browse files · 1 file·+37 added−33 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+37 added−33 removed
- other:+37 added−33 removed
Provenance
- Commit
b57482d- Tree
c3fa24a- Author
Tom Christie <tom@tomchristie.com>- Committer
Tom Christie <tom@tomchristie.com>- Parent
9f58afd
1 file changed+37 added−33 removed
modified:httpx/_transports/urllib3.py+37 added-33 removed
1 import socket2-import ssl3-from typing import Dict, Iterator, List, Optional, Tuple, Union2+from typing import Dict, Iterator, List, Optional, Tuple3 4 import httpcore5 6 from .._config import Proxy, SSLConfig21 unmodified lines28 pool_block: bool = False,29 ):30 assert (31 urllib3 is not None33- ), "urllib3 must be installed separately in order to use URLLib3Transport"32+ ), "urllib3 must be installed in order to use URLLib3Transport"33 34 ssl_config = SSLConfig(35 verify=verify, cert=cert, trust_env=trust_env, http2=False36 )37 39- self.pool = self.init_pool_manager(40- proxy=proxy,38+ self.pool = urllib3.PoolManager(39 ssl_context=ssl_config.ssl_context,42- pool_connections=pool_connections,43- pool_maxsize=pool_maxsize,44- pool_block=pool_block,40+ num_pools=pool_connections,41+ maxsize=pool_maxsize,42+ block=pool_block,43 )44 47- def init_pool_manager(48- self,49- proxy: Optional[Proxy],50- ssl_context: ssl.SSLContext,51- pool_connections: int,52- pool_maxsize: int,53- pool_block: bool,54- ) -> Union[urllib3.PoolManager, urllib3.ProxyManager]:55- if proxy is None:56- return urllib3.PoolManager(57- ssl_context=ssl_context,58- num_pools=pool_connections,59- maxsize=pool_maxsize,60- block=pool_block,61- )62- else:63- return urllib3.ProxyManager(64- proxy_url=str(proxy.url),65- proxy_headers=dict(proxy.headers),66- ssl_context=ssl_context,67- num_pools=pool_connections,68- maxsize=pool_maxsize,69- block=pool_block,70- )71-45 def request(46 self,47 method: bytes,48 url: Tuple[bytes, bytes, Optional[int], bytes],68 unmodified lines117 return (b"HTTP/1.1", status_code, conn.reason, headers, response_stream)118 119 def close(self) -> None:120 self.pool.clear()121+122+123+class URLLib3ProxyTransport(URLLib3Transport):124+ def __init__(125+ self,126+ *,127+ proxy_url: str,128+ proxy_headers: dict = None,129+ verify: VerifyTypes = True,130+ cert: CertTypes = None,131+ trust_env: bool = None,132+ pool_connections: int = 10,133+ pool_maxsize: int = 10,134+ pool_block: bool = False,135+ ):136+ assert (137+ urllib3 is not None138+ ), "urllib3 must be installed in order to use URLLib3ProxyTransport"139+140+ ssl_config = SSLConfig(141+ verify=verify, cert=cert, trust_env=trust_env, http2=False142+ )143+144+ self.pool = urllib3.ProxyManager(145+ proxy_url=proxy_url,146+ proxy_headers=proxy_headers,147+ ssl_context=ssl_config.ssl_context,148+ num_pools=pool_connections,149+ maxsize=pool_maxsize,150+ block=pool_block,151+ )