2121 resolve_cafile ,
2222)
2323from ._crl import CRLValidator
24+ from ..url_util import should_bypass_proxies
2425from ._ocsp_asn1crypto import SnowflakeOCSPAsn1Crypto
2526
2627if TYPE_CHECKING :
@@ -439,7 +440,7 @@ def from_config(cls, cfg: AioHttpConfig, **overrides: Any) -> SessionManager:
439440 cfg = cfg .copy_with (** overrides )
440441 return cls (config = cfg )
441442
442- def make_session (self ) -> aiohttp .ClientSession :
443+ def make_session (self , * , url : str | None = None ) -> aiohttp .ClientSession :
443444 """Create a new aiohttp.ClientSession with configured connector."""
444445 connector = self ._cfg .get_connector (
445446 session_manager = self .clone (),
@@ -456,24 +457,18 @@ async def use_session(
456457 self , url : str | bytes , use_pooling : bool | None = None
457458 ) -> AsyncGenerator [aiohttp .ClientSession ]:
458459 """
459- Async version of use_session yielding aiohttp.ClientSession.
460460 'url' is an obligatory parameter due to the need for correct proxy handling (i.e. bypassing caused by no_proxy settings).
461461 """
462462 use_pooling = use_pooling if use_pooling is not None else self .use_pooling
463463 if not use_pooling :
464- session = self .make_session ()
464+ session = self .make_session (url = url )
465465 try :
466466 yield session
467467 finally :
468468 await session .close ()
469469 else :
470- hostname = urlparse (url ).hostname if url else None
471- pool = self ._sessions_map [hostname ]
472- session = pool .get_session ()
473- try :
474- yield session
475- finally :
476- pool .return_session (session )
470+ with self ._yield_session_from_pool (url ) as session_from_pool :
471+ yield session_from_pool
477472
478473 async def request (
479474 self ,
@@ -585,16 +580,22 @@ def request(
585580 )
586581 return super ().request (method , url , ** kwargs )
587582
588- def make_session (self ) -> aiohttp .ClientSession :
583+ def make_session (self , * , url : str | None = None ) -> aiohttp .ClientSession :
589584 connector = self ._cfg .get_connector (
590585 session_manager = self .clone (),
591586 snowflake_ocsp_mode = self ._cfg .snowflake_ocsp_mode ,
592587 )
588+ # We use requests.utils here (in asynch code) to keep the behaviour uniform for synch and asynch code. If we wanted each version to depict its http library's behaviour, we could use here: aiohttp.helpers.proxy_bypass(url, proxies={...}) here
589+ proxy = (
590+ None
591+ if should_bypass_proxies (url , no_proxy = self .config .no_proxy )
592+ else self .proxy_url
593+ )
593594 # Construct session with base proxy set, request() may override per-URL when bypassing
594595 return self .SessionWithProxy (
595596 connector = connector ,
596597 trust_env = self ._cfg .trust_env ,
597- proxy = self . proxy_url ,
598+ proxy = proxy ,
598599 )
599600
600601
0 commit comments