Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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/9870.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added support for the ``partitioned`` attribute in the ``set_cookie`` method.
4 changes: 4 additions & 0 deletions aiohttp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,7 @@ def set_cookie(
secure: Optional[bool] = None,
httponly: Optional[bool] = None,
samesite: Optional[str] = None,
partitioned: Optional[bool] = None,
) -> None:
"""Set or update response cookie.

Expand Down Expand Up @@ -974,6 +975,9 @@ def set_cookie(
if samesite is not None:
c["samesite"] = samesite

if partitioned is not None:
c["partitioned"] = partitioned

if DEBUG:
cookie_length = len(c.output(header="")[1:])
if cookie_length > COOKIE_MAX_LENGTH:
Expand Down
8 changes: 7 additions & 1 deletion docs/web_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,8 @@ and :ref:`aiohttp-web-signals` handlers::

.. method:: set_cookie(name, value, *, path='/', expires=None, \
domain=None, max_age=None, \
secure=None, httponly=None, samesite=None)
secure=None, httponly=None, samesite=None, \
partitioned=None)

Convenient way for setting :attr:`cookies`, allows to specify
some additional properties like *max_age* in a single call.
Expand Down Expand Up @@ -753,6 +754,11 @@ and :ref:`aiohttp-web-signals` handlers::

.. versionadded:: 3.7

:param bool partitioned: ``True`` to set a partitioned cookie.
Available in Python 3.14+. (optional)

.. versionadded:: 3.12

.. method:: del_cookie(name, *, path='/', domain=None)

Deletes cookie.
Expand Down
13 changes: 13 additions & 0 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,19 @@ def test_cookies_mixin_path() -> None:
)


@pytest.mark.skipif(sys.version_info < (3, 14), reason="No partitioned support")
def test_cookies_mixin_partitioned() -> None:
sut = CookieImplementation()

assert sut.cookies == {}

sut.set_cookie("name", "value", partitioned=False)
assert str(sut.cookies) == "Set-Cookie: name=value; Path=/"

sut.set_cookie("name", "value", partitioned=True)
assert str(sut.cookies) == "Set-Cookie: name=value; Partitioned; Path=/"


def test_sutonse_cookie__issue_del_cookie() -> None:
sut = CookieImplementation()

Expand Down
Loading