Skip to content

Response.delete_cookie accepts cookie options#1228

Merged
Kludex merged 3 commits intoKludex:masterfrom
BookGin:fix-1207
Oct 5, 2021
Merged

Response.delete_cookie accepts cookie options#1228
Kludex merged 3 commits intoKludex:masterfrom
BookGin:fix-1207

Conversation

@BookGin
Copy link
Copy Markdown
Contributor

@BookGin BookGin commented Jul 2, 2021

Though functools.partial could be used, it needs to be instantiated somewhere. Otherwise it will introduce the overhead of function object every time.

Let's just follow werkzeug's implementation.

@BookGin BookGin changed the title Fix #1207 Response.delete_cookie accpets cookie options Jul 2, 2021
@Kludex
Copy link
Copy Markdown
Owner

Kludex commented Sep 25, 2021

@BookGin What do you mean by: "Though functools.partial could be used, it needs to be instantiated somewhere."?

Thanks for the PR! 🎉

@BookGin
Copy link
Copy Markdown
Contributor Author

BookGin commented Sep 28, 2021

Like this pseudo-code, so we need to instantiate the partial function somewhere.....

from functools import partial
def delete_cookie(
       self,
       key: str,
       path: str = "/",
       domain: str = None,
       secure: bool = False,
       httponly: bool = False,
       samesite: str = "lax",
   ) -> None:
   if not hasattr(delete_cookie, '_func'):
       delete_cookie._func = partial(self.set_cookie, max_age=0, expires=0)
   return delete_cookie._func(path, domain, secure, httponly, samesite)

Never mind. I don't think it's more readable. Let's just keep things simple.

@Kludex Kludex changed the title Response.delete_cookie accpets cookie options Response.delete_cookie accepts cookie options Sep 28, 2021
@Kludex
Copy link
Copy Markdown
Owner

Kludex commented Oct 5, 2021

@BookGin Thanks for the PR! 🎉

@Kludex Kludex merged commit ada99be into Kludex:master Oct 5, 2021
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.

2 participants