Skip to content

Commit

Permalink
Improve performance of default auth (#9466)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Oct 11, 2024
1 parent 2b13e3b commit 03851d1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES/9466.feature.rst
13 changes: 10 additions & 3 deletions aiohttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ class ClientSession:

__slots__ = (
"_base_url",
"_base_url_origin",
"_source_traceback",
"_connector",
"_loop",
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 03851d1

Please sign in to comment.