Skip to content

Fix lifetime in cookies returned from Cookies::list, so they can be used with Cookies::remove#40

Open
benw wants to merge 2 commits intoimbolc:mainfrom
benw:main
Open

Fix lifetime in cookies returned from Cookies::list, so they can be used with Cookies::remove#40
benw wants to merge 2 commits intoimbolc:mainfrom
benw:main

Conversation

@benw
Copy link

@benw benw commented Oct 19, 2025

Adds an example demonstrating the problem, and then a commit to fix it. See explanation in individual commits.

Fixes #14.

benw added 2 commits October 19, 2025 21:32
This example demonstrates that currently the cookies returned
by `Cookies::list` are incompatible with `Cookies::remove`.
This will be fixed in the next commit.

```
error[E0597]: `cookies` does not live long enough
  --> examples/remove_all.rs:19:15
   |
18 | async fn handler(cookies: Cookies) {
   |                  ------- binding `cookies` declared here
19 |     let all = cookies.list();
   |               ^^^^^^^ borrowed value does not live long enough
20 |     for cookie in all {
21 |         cookies.remove(cookie);
   |         ---------------------- argument requires that `cookies` is borrowed for `'static`
22 |     }
23 | }
   | - `cookies` dropped here while still borrowed
```
The cookies in the jar were already 'static, but that fact was
lost by the declaration of the return type.

Fixes imbolc#14
@benw
Copy link
Author

benw commented Oct 19, 2025

Sadly this still doesn't reliably delete all cookies, I think because domain / path etc are not propagated in the underlying cookie implementation.

@imbolc
Copy link
Owner

imbolc commented Oct 20, 2025

I guess nowadays you can just use Clear-Site-Data: "cookies" header to remove all cookies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Question] How to remove cookies?

2 participants