Skip to content
Myr

Use URLLib3 configuration options for URLLib3 transport (#970)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Use URLLib3 configuration options for URLLib3 transport * Drop redundant code

authored by Tom Christie · committed by GitHub · parent 99a5c78 · Browse files · 1 file+22 added−34 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+22 added−34 removed

  • other:+22 added−34 removed

1 file+22 added−34 removed

modified:httpx/_transports/urllib3.py+22 added-34 removed
1import math1import socket2import ssl3from typing import Dict, Iterator, List, Optional, Tuple, Union45import httpcore68from .._config import DEFAULT_POOL_LIMITS, PoolLimits, Proxy, SSLConfig7from .._config import Proxy, SSLConfig8from .._content_streams import ByteStream, IteratorStream9from .._types import CertTypes, VerifyTypes10from .._utils import as_network_error, warn_deprecated11
11 unmodified lines
23 proxy: Proxy = None,24 verify: VerifyTypes = True,25 cert: CertTypes = None,26 trust_env: bool = None,28 pool_limits: PoolLimits = DEFAULT_POOL_LIMITS,27 pool_connections: int = 10,28 pool_maxsize: int = 10,29 pool_block: bool = False,30 ):31 assert (32 urllib3 is not None33 ), "urllib3 must be installed separately in order to use URLLib3Transport"3435 ssl_config = SSLConfig(36 verify=verify, cert=cert, trust_env=trust_env, http2=False37 )37 max_connections = pool_limits.max_connections38 max_keepalive = pool_limits.max_keepalive3840 # Our connection pool configuration doesn't quite match up with urllib3's41 # controls, but we can put sensible mappings in place:42 if max_connections is None:43 block = False44 if max_keepalive is None:45 num_pools = 100046 maxsize = 100047 else:48 num_pools = int(math.sqrt(max_keepalive))49 maxsize = int(math.sqrt(max_keepalive))50 else:51 block = True52 num_pools = int(math.sqrt(max_connections))53 maxsize = int(math.sqrt(max_connections))5439 self.pool = self.init_pool_manager(40 proxy=proxy,41 ssl_context=ssl_config.ssl_context,58 num_pools=num_pools,59 maxsize=maxsize,60 block=block,42 pool_connections=pool_connections,43 pool_maxsize=pool_maxsize,44 pool_block=pool_block,45 )4647 def init_pool_manager(48 self,49 proxy: Optional[Proxy],50 ssl_context: ssl.SSLContext,67 num_pools: int,68 maxsize: int,69 block: bool,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,74 num_pools=num_pools,75 maxsize=maxsize,76 block=block,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,83 num_pools=num_pools,84 maxsize=maxsize,85 block=block,67 num_pools=pool_connections,68 maxsize=pool_maxsize,69 block=pool_block,70 )7172 def request(73 self,
80 unmodified lines
154 proxy: Proxy = None,155 verify: VerifyTypes = True,156 cert: CertTypes = None,157 trust_env: bool = None,174 pool_limits: PoolLimits = DEFAULT_POOL_LIMITS,158 pool_connections: int = 10,159 pool_maxsize: int = 10,160 pool_block: bool = False,161 ):162 warn_deprecated("URLLib3Dispatch is deprecated, please use URLLib3Transport")163 super().__init__(164 proxy=proxy,165 verify=verify,166 cert=cert,167 trust_env=trust_env,182 pool_limits=pool_limits,168 pool_connections=pool_connections,169 pool_maxsize=pool_maxsize,170 pool_block=pool_block,171 )