From 03851d1353f66b4b40593a03c7d5f14b16122944 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 11 Oct 2024 09:19:24 -0500 Subject: [PATCH] Improve performance of default auth (#9466) --- CHANGES/9466.feature.rst | 1 + aiohttp/client.py | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) create mode 120000 CHANGES/9466.feature.rst diff --git a/CHANGES/9466.feature.rst b/CHANGES/9466.feature.rst new file mode 120000 index 00000000000..a54874e90e0 --- /dev/null +++ b/CHANGES/9466.feature.rst @@ -0,0 +1 @@ +8966.feature.rst \ No newline at end of file diff --git a/aiohttp/client.py b/aiohttp/client.py index 3546b7462c5..05476f6fccd 100644 --- a/aiohttp/client.py +++ b/aiohttp/client.py @@ -231,6 +231,7 @@ class ClientSession: __slots__ = ( "_base_url", + "_base_url_origin", "_source_traceback", "_connector", "_loop", @@ -295,10 +296,12 @@ def __init__( self._connector: Optional[BaseConnector] = None if base_url is None or isinstance(base_url, URL): self._base_url: Optional[URL] = base_url + self._base_url_origin = None if base_url is None else base_url.origin() else: self._base_url = URL(base_url) + self._base_url_origin = self._base_url.origin() assert ( - self._base_url.origin() == self._base_url + self._base_url_origin == self._base_url ), "Only absolute URLs without path part are supported" loop = asyncio.get_running_loop() @@ -566,8 +569,12 @@ async def _request( if auth is None: auth = auth_from_url - if auth is None and ( - not self._base_url or self._base_url.origin() == url.origin() + if ( + auth is None + and self._default_auth + and ( + not self._base_url or self._base_url_origin == url.origin() + ) ): auth = self._default_auth # It would be confusing if we support explicit