mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 02:31:04 +01:00
fix #1877
This commit is contained in:
parent
677ddd7539
commit
3b95c85d3d
|
@ -5498,19 +5498,31 @@ func (ctx *Context) UpsertCookie(cookie *http.Cookie, options ...CookieOption) b
|
|||
ctx.applyCookieOptions(cookie, OpCookieSet, options)
|
||||
|
||||
header := ctx.ResponseWriter().Header()
|
||||
|
||||
if cookies := header[setCookieHeaderKey]; len(cookies) > 0 {
|
||||
s := cookie.Name + "=" // name=?value
|
||||
|
||||
existingUpdated := false
|
||||
|
||||
for i, c := range cookies {
|
||||
if strings.HasPrefix(c, s) {
|
||||
if existingUpdated { // fixes #1877
|
||||
// remove any duplicated.
|
||||
cookies[i] = ""
|
||||
header[setCookieHeaderKey] = cookies
|
||||
continue
|
||||
}
|
||||
// We need to update the Set-Cookie (to update the expiration or any other cookie's properties).
|
||||
// Probably the cookie is set and then updated in the first session creation
|
||||
// (e.g. UpdateExpiration, see https://github.com/kataras/iris/issues/1485).
|
||||
cookies[i] = cookie.String()
|
||||
header[setCookieHeaderKey] = cookies
|
||||
return false
|
||||
existingUpdated = true
|
||||
}
|
||||
}
|
||||
|
||||
if existingUpdated {
|
||||
return false // existing one updated.
|
||||
}
|
||||
}
|
||||
|
||||
header.Add(setCookieHeaderKey, cookie.String())
|
||||
|
|
|
@ -268,7 +268,7 @@ func (s *Sessions) Destroy(ctx *context.Context) {
|
|||
|
||||
ctx.Values().Remove(sessionContextKey)
|
||||
|
||||
ctx.RemoveCookie(s.config.Cookie)
|
||||
ctx.RemoveCookie(s.config.Cookie, s.cookieOptions...)
|
||||
s.provider.Destroy(cookieValue)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user