Skip to content

Commit 4e0d39f

Browse files
committed
cleanup
1 parent c703eb4 commit 4e0d39f

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

services/web/server/src/simcore_service_webserver/session/_cookie_storage.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,12 @@
1414

1515

1616
def _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

Comments
 (0)