From fb8d8d0881b566f7856d6075c458851624f74822 Mon Sep 17 00:00:00 2001 From: "Gerasimos (Makis) Maropoulos" Date: Mon, 25 Dec 2023 23:55:31 +0200 Subject: [PATCH] fix #2309 --- context/context.go | 26 ++++++++++++++------------ core/memstore/lifetime.go | 2 +- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/context/context.go b/context/context.go index 80c0e72b..23ef6b50 100644 --- a/context/context.go +++ b/context/context.go @@ -5946,23 +5946,25 @@ var ( CookieExpireUnlimited = time.Now().AddDate(24, 10, 10) ) -// RemoveCookie deletes a cookie by its name and path = "/". -// Tip: change the cookie's path to the current one by: RemoveCookie("name", iris.CookieCleanPath) +// RemoveCookie deletes a cookie by its name. It reads the cookie's path and domain +// in order to delete the cookie cross-browser. +// Reports whether the cookie was removed or not. // // Example: https://github.com/kataras/iris/tree/main/_examples/cookies/basic -func (ctx *Context) RemoveCookie(name string, options ...CookieOption) { - c := &http.Cookie{} - c.Name = name - c.Value = "" - c.Path = "/" // if user wants to change it, use of the CookieOption `CookiePath` is required if not `ctx.SetCookie`. - c.HttpOnly = true - - // RFC says 1 second, but let's do it 1 to make sure is working - c.Expires = CookieExpireDelete - c.MaxAge = -1 +func (ctx *Context) RemoveCookie(name string, options ...CookieOption) bool { + // Get the cookie from the request + c, err := ctx.Request().Cookie(name) + if err != nil { + return false + } + // Set the cookie expiration date to a past time + c.Expires = time.Unix(0, 0) + c.MaxAge = -1 // RFC says 1 second, but let's do it -1 to make sure is working. + // Send the cookie back to the client ctx.applyCookieOptions(c, OpCookieDel, options) http.SetCookie(ctx.writer, c) + return true } // VisitAllCookies takes a visitor function which is called diff --git a/core/memstore/lifetime.go b/core/memstore/lifetime.go index 070f372f..11d7a38d 100644 --- a/core/memstore/lifetime.go +++ b/core/memstore/lifetime.go @@ -13,7 +13,7 @@ var ( Clock func() time.Time = time.Now // ExpireDelete may be set on Cookie.Expire for expiring the given cookie. - ExpireDelete = time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC) + ExpireDelete = time.Unix(0, 0) // time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC) ) // LifeTime controls the session expiration datetime.