mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 02:31:04 +01:00
fix #2309
This commit is contained in:
parent
26422ebaf4
commit
fb8d8d0881
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue
Block a user