-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
🐛 [Bug]: (c *fiber.Ctx).ClearCookie() does absolutely nothing #2878
Comments
Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord |
I think the problem is that when unsetting the cookie, the header looks like this:
I remember that the other fields need to perfectly match to clear a cookie. |
The // DelClientCookie instructs the client to remove the given cookie.
// This doesn't work for a cookie with specific domain or path,
// you should delete it manually like:
//
// c := AcquireCookie()
// c.SetKey(key)
// c.SetDomain("example.com")
// c.SetPath("/path")
// c.SetExpire(CookieExpireDelete)
// h.SetCookie(c)
// ReleaseCookie(c)
//
// Use DelCookie if you want just removing the cookie from response header.
func (h *ResponseHeader) DelClientCookie(key string) {
h.DelCookie(key)
c := AcquireCookie()
c.SetKey(key)
c.SetExpire(CookieExpireDelete)
h.SetCookie(c)
ReleaseCookie(c)
} Maybe the problem happens when the cookie has a path. Maybe new method to delete the cookie manually by passing a |
Original issue: valyala/fasthttp#951 |
I ended up using this utility func ClearCookies(c *fiber.Ctx, key ...string) {
for i := range key {
c.Cookie(&fiber.Cookie{
Name: key[i],
Expires: time.Now().Add(-time.Hour * 24),
Value: "",
})
}
} and use it like utils.ClearCookies(c, "token_account") |
@ReneWerner87 Could we incorporate the above in the framework? |
Bug Description
Setting the cookie is fine. The gofiber server responds with this header, which sets the cookie.
However, the server can't reset it.
Neither
c.ClearCookie(name)
orc.ClearCookie()
work.How to Reproduce
Steps to reproduce the behavior:
c.ClearCookie
Expected Behavior
cookie cleared
Fiber Version
v2.52.0
Workaround
Set the cookie with no value and an expiration date in the past.
Checklist:
The text was updated successfully, but these errors were encountered: