Skip to content

Commit

Permalink
Improve performance of default auth (#9466)
Browse files Browse the repository at this point in the history
(cherry picked from commit 03851d1)
  • Loading branch information
bdraco committed Oct 11, 2024
1 parent 14bdfc6 commit f7f6a09
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 @@ -230,6 +230,7 @@ class ClientSession:
ATTRS = frozenset(
[
"_base_url",
"_base_url_origin",
"_source_traceback",
"_connector",
"_loop",
Expand Down Expand Up @@ -309,10 +310,12 @@ def __init__(

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"

if timeout is sentinel or timeout is None:
Expand Down Expand Up @@ -620,8 +623,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 f7f6a09

Please sign in to comment.