1414
1515
1616def _share_cookie_across_all_subdomains (
17- response : web .StreamResponse , params : aiohttp_session ._CookieParams
17+ request : web .BaseRequest , params : aiohttp_session ._CookieParams
1818) -> aiohttp_session ._CookieParams :
1919 """
2020 Shares cookie across all subdomains, by appending a dot (`.`) in front of the domain name
2121 overwrite domain from `None` (browser sets `example.com`) to `.example.com`
2222 """
23- request = response ._req # pylint:disable=protected-access # noqa: SLF001
24- assert isinstance (request , web .Request ) # nosec
25-
2623 if (host := request .url .host ) and host is not None :
2724 params ["domain" ] = f".{ host .lstrip ('.' )} "
2825
@@ -48,14 +45,18 @@ def save_cookie(
4845 * ,
4946 max_age : int | None = None ,
5047 ) -> None :
51- params = _share_cookie_across_all_subdomains (
52- response , self ._cookie_params .copy ()
53- )
5448
55- # WARNING: the code below is taken and adapted from the superclass implementation `EncryptedCookieStorage.save_cookie`
49+ params = self ._cookie_params .copy ()
50+ if request := response ._req : # pylint:disable=protected-access # noqa: SLF001
51+ params = _share_cookie_across_all_subdomains (request , params )
52+
53+ # --------------------------------------------------------
54+ # WARNING: the code below is taken and adapted from the superclass
55+ # implementation `EncryptedCookieStorage.save_cookie`
5656 # Adjust in case the base library changes.
5757 assert aiohttp_session .__version__ == "2.11.0" # nosec
58- # ---
58+ # --------------------------------------------------------
59+
5960 if max_age is not None :
6061 params ["max_age" ] = max_age
6162 t = time .gmtime (time .time () + max_age )
0 commit comments