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

Skip filtering CookieJar when the jar is empty or all cookies have expired #7819

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/7819.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Skip filtering ``CookieJar`` when the jar is empty or all cookies have expired.
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ Robert Lu
Robert Nikolich
Roman Markeloff
Roman Podoliaka
Rong Zhang
Samir Akarioh
Samuel Colvin
Sean Hunt
Expand Down
11 changes: 10 additions & 1 deletion aiohttp/cookiejar.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ def filter_cookies(
self, request_url: URL = URL()
) -> Union["BaseCookie[str]", "SimpleCookie[str]"]:
"""Returns this jar's cookies filtered by their attributes."""
self._do_expiration()
if not isinstance(request_url, URL):
warnings.warn(
"The method accepts yarl.URL instances only, got {}".format(
Expand All @@ -246,6 +245,16 @@ def filter_cookies(
filtered: Union["SimpleCookie[str]", "BaseCookie[str]"] = (
SimpleCookie() if self._quote_cookie else BaseCookie()
)
if not self._cookies:
# Shortcut: empty jar
# We need the shortcut because the filtering itself and its
# preparation is expensive
return filtered
self._do_expiration()
if not self._cookies:
# Shortcut: all cookies expired
# Likewise.
return filtered
hostname = request_url.raw_host or ""
request_origin = URL()
with contextlib.suppress(ValueError):
Expand Down