Skip to content

Commit

Permalink
Avoid calling update_cookies when there are no cookies (#9470)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Oct 11, 2024
1 parent 8a4707e commit 5bded30
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES/9470.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improved performance of the client request lifecycle when there are no cookies -- by :user:`bdraco`.
5 changes: 3 additions & 2 deletions aiohttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def __init__(
cookie_jar = CookieJar()
self._cookie_jar = cookie_jar

if cookies is not None:
if cookies:
self._cookie_jar.update_cookies(cookies)

self._connector_owner = connector_owner
Expand Down Expand Up @@ -679,7 +679,8 @@ async def _request(
raise
raise ClientOSError(*exc.args) from exc

self._cookie_jar.update_cookies(resp.cookies, resp.url)
if cookies := resp.cookies:
self._cookie_jar.update_cookies(cookies, resp.url)

# redirects
if resp.status in (301, 302, 303, 307, 308) and allow_redirects:
Expand Down

0 comments on commit 5bded30

Please sign in to comment.