Skip to content

Commit cc4f6f5

Browse files
Add samesite support. (#575)
1 parent 013ad47 commit cc4f6f5

File tree

7 files changed

+16
-8
lines changed

7 files changed

+16
-8
lines changed

aiohttp_session/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class _CookieParams(TypedDict, total=False):
2626
path: str
2727
secure: Optional[bool]
2828
httponly: bool
29+
samesite: Optional[str]
2930
expires: str
3031

3132

@@ -219,6 +220,7 @@ def __init__(
219220
path: str = '/',
220221
secure: Optional[bool] = None,
221222
httponly: bool = True,
223+
samesite: Optional[str] = None,
222224
encoder: Callable[[object], str] = json.dumps,
223225
decoder: Callable[[str], Any] = json.loads
224226
) -> None:
@@ -228,7 +230,8 @@ def __init__(
228230
max_age=max_age,
229231
path=path,
230232
secure=secure,
231-
httponly=httponly
233+
httponly=httponly,
234+
samesite=samesite
232235
)
233236
self._max_age = max_age
234237
self._encoder = encoder
@@ -305,12 +308,13 @@ def __init__(
305308
path: str = '/',
306309
secure: Optional[bool] = None,
307310
httponly: bool = True,
311+
samesite: Optional[str] = None,
308312
encoder: Callable[[object], str] = json.dumps,
309313
decoder: Callable[[str], Any] = json.loads
310314
) -> None:
311315
super().__init__(cookie_name=cookie_name, domain=domain,
312316
max_age=max_age, path=path, secure=secure,
313-
httponly=httponly,
317+
httponly=httponly, samesite=samesite,
314318
encoder=encoder, decoder=decoder)
315319

316320
async def load_session(self, request: web.Request) -> Session:

aiohttp_session/cookie_storage.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ def __init__(
2323
path: str = '/',
2424
secure: Optional[bool] = None,
2525
httponly: bool = True,
26+
samesite: Optional[str] = None,
2627
encoder: Callable[[object], str] = json.dumps,
2728
decoder: Callable[[str], Any] = json.loads
2829
) -> None:
2930
super().__init__(cookie_name=cookie_name, domain=domain,
3031
max_age=max_age, path=path, secure=secure,
31-
httponly=httponly,
32+
httponly=httponly, samesite=samesite,
3233
encoder=encoder, decoder=decoder)
3334

3435
if isinstance(secret_key, str):

aiohttp_session/memcached_storage.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ def __init__( # type: ignore[no-any-unimported] # TODO: aiomcache
2121
path: str = '/',
2222
secure: Optional[bool] = None,
2323
httponly: bool = True,
24+
samesite: Optional[str] = None,
2425
key_factory: Callable[[], str] = lambda: uuid.uuid4().hex,
2526
encoder: Callable[[object], str] = json.dumps,
2627
decoder: Callable[[str], Any] = json.loads
2728
) -> None:
2829
super().__init__(cookie_name=cookie_name, domain=domain,
2930
max_age=max_age, path=path, secure=secure,
30-
httponly=httponly,
31+
httponly=httponly, samesite=samesite,
3132
encoder=encoder, decoder=decoder)
3233
self._key_factory = key_factory
3334
self.conn = memcached_conn

aiohttp_session/nacl_storage.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ def __init__(
2525
path: str = '/',
2626
secure: Optional[bool] = None,
2727
httponly: bool = True,
28+
samesite: Optional[str] = None,
2829
encoder: Callable[[object], str] = json.dumps,
2930
decoder: Callable[[str], Any] = json.loads
3031
) -> None:
3132
super().__init__(cookie_name=cookie_name, domain=domain,
3233
max_age=max_age, path=path, secure=secure,
33-
httponly=httponly,
34+
httponly=httponly, samesite=samesite,
3435
encoder=encoder, decoder=decoder)
3536

3637
self._secretbox = nacl.secret.SecretBox(secret_key)

aiohttp_session/redis_storage.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ def __init__(
2525
path: str = '/',
2626
secure: Optional[bool] = None,
2727
httponly: bool = True,
28+
samesite: Optional[str] = None,
2829
key_factory: Callable[[], str] = lambda: uuid.uuid4().hex,
2930
encoder: Callable[[object], str] = json.dumps,
3031
decoder: Callable[[str], Any] = json.loads
3132
) -> None:
3233
super().__init__(cookie_name=cookie_name, domain=domain,
3334
max_age=max_age, path=path, secure=secure,
34-
httponly=httponly,
35+
httponly=httponly, samesite=samesite,
3536
encoder=encoder, decoder=decoder)
3637
if aioredis is None:
3738
raise RuntimeError("Please install aioredis")

requirements-dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pytest-aiohttp==0.3.0
1616
pytest-cov==3.0.0
1717
pytest-mock==3.6.1
1818
pytest-sugar==0.9.4
19-
aiohttp<3.9
19+
aiohttp==3.8
2020
multidict==5.2.0
2121
chardet==4.0.0
2222
yarl==1.7.2

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def read(f):
1616
return open(os.path.join(os.path.dirname(__file__), f)).read().strip()
1717

1818

19-
install_requires = ['aiohttp>=3.0.1', 'typing_extensions>=3.7.4; python_version<"3.8"']
19+
install_requires = ['aiohttp>=3.8', 'typing_extensions>=3.7.4; python_version<"3.8"']
2020
extras_require = {
2121
'aioredis': ['aioredis>=1.0.0'],
2222
'aiomcache': ['aiomcache>=0.5.2'],

0 commit comments

Comments
 (0)