Support split across Response.delete_cookie
https://github.com/Kludex/starlette/pull/3376
Purpose
Response.set_cookie accepts the partitioned flag, but its counterpart, Response.delete_cookie, does not. To delete partitioned cookies (CHIPS), the Set-Cookie header for expiration must also include the Partitioned attribute. Since browsers store Partitioned as part of the cookie’s identifier, a deletion header missing this attribute will not match the existing cookie, causing the cookie to remain.
This PR adds the partitioned: bool = False argument to delete_cookie and passes it directly to set_cookie along with other attributes, aligning the argument structures of the two methods. In versions prior to Python 3.14, the version check that triggers ValueError is already included within set_cookie, so no separate handling was added.
Changes
starlette/responses.py— Added thepartitionedargument todelete_cookieand passed it toset_cookie(+2)tests/test_responses.py— Addedtest_delete_cookie_partitioned. Verifies whetherPartitionedappears in the header for Python 3.14 and later, and whetherValueErroroccurs for earlier versions (+18)docs/responses.md— Updated the signature fordelete_cookie. The existing documentation was outdated and lackedsecure,httponly, andsamesite; added an example of deleting partition cookies along with the mandatorySecurewarning (+18 / -1)
response = Response()
response.delete_cookie("session", secure=True, samesite="none", partitioned=True)
Testing
$ pytest tests/test_responses.py -k cookie
18 passed
$ ruff format --check starlette tests # already formatted
$ ruff check starlette tests # All checks passed
$ mypy starlette # no issues
Since the local interpreter is Python 3.13, I ran only the paths for versions prior to 3.14 locally, and verified the paths for 3.14 and later using the CI matrix.
Review Responses
- Documentation issue — Following a comment that the
delete_cookiedocumentation lacked an explanation ofpartitioned, I added it in a subsequent commit. - Proposal to automatically enable
securewhenpartitioned=Trueis used — I did not implement this. We follow the convention of passing attributes as-is; for example,set_cookiedoes not enforcesecure, and Starlette does not enforcesecureeven forsamesite="none". Since enforcing it only fordelete_cookiewould cause the two methods to behave differently, it was decided to leave the code as is and add a warning in the documentation stating thatSecureis required.
Result
Submitted on July 13, 2026; merged into main by the maintainer (Kludex) on September 5, 2026. The scope of changes was 3 files, +38 / -1.