Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of default auth #9466

Merged
merged 2 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading