Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Response): support Partitioned cookie attribute #2248

Merged
merged 6 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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 docs/_newsfragments/2213.newandimproved.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added kwarg ``partitioned`` to :py:meth:`~falcon.Response.unset_cookie` to set the Partitioned setting on the cookie
M-Mueller marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 4 additions & 4 deletions falcon/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@
# the self.content_length property.
self._headers['content-length'] = str(content_length)

def set_cookie(
def set_cookie( # noqa: C901
self,
name,
value,
Expand Down Expand Up @@ -455,7 +455,7 @@
https://site-b.example. While this attribute is not yet
standardized, it is already used by Chrome.

(See also: `Partitioned RFC Draft`_)
(See also: `CHIPS`_)
Raises:
KeyError: `name` is not a valid cookie name.
ValueError: `value` is not a valid cookie value.
Expand All @@ -466,8 +466,8 @@
.. _Same-Site RFC Draft:
https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.7

.. _Partitioned RFC Draft:
https://datatracker.ietf.org/doc/html/draft-cutler-httpbis-partitioned-cookies#section-2.1
.. _CHIPS:
https://developer.mozilla.org/en-US/docs/Web/Privacy/Privacy_sandbox/Partitioned_cookies

"""

Expand Down Expand Up @@ -541,7 +541,7 @@
self._cookies[name]['samesite'] = same_site.capitalize()

if partitioned:
self._cookies[name]['partitioned'] = True

Check warning on line 544 in falcon/response.py

View check run for this annotation

Codecov / codecov/patch

falcon/response.py#L544

Added line #L544 was not covered by tests

def unset_cookie(self, name, samesite='Lax', domain=None, path=None):
"""Unset a cookie in the response.
Expand Down
4 changes: 2 additions & 2 deletions falcon/testing/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@
same_site (str): Specifies whether cookies are send in
cross-site requests. Possible values are 'Lax', 'Strict'
and 'None'. ``None`` if not specified.
partitioned (bool): Whether third-party cookies should be stored
with 2 keys.
partitioned (bool): Indicates if the cookie has the Partitioned
flag set
"""

def __init__(self, morsel):
Expand All @@ -118,7 +118,7 @@
'secure',
'httponly',
'samesite',
'partitioned',

Check warning on line 121 in falcon/testing/client.py

View check run for this annotation

Codecov / codecov/patch

falcon/testing/client.py#L121

Added line #L121 was not covered by tests
):
value = morsel[name.replace('_', '-')] or None
setattr(self, '_' + name, value)
Expand Down
Loading