This commit is contained in:
Gerasimos (Makis) Maropoulos 2022-04-23 23:26:25 +03:00
parent 677ddd7539
commit 3b95c85d3d
No known key found for this signature in database
GPG Key ID: 66FCC29BD385FCA6
2 changed files with 15 additions and 3 deletions

View File

@ -5498,19 +5498,31 @@ func (ctx *Context) UpsertCookie(cookie *http.Cookie, options ...CookieOption) b
ctx.applyCookieOptions(cookie, OpCookieSet, options) ctx.applyCookieOptions(cookie, OpCookieSet, options)
header := ctx.ResponseWriter().Header() header := ctx.ResponseWriter().Header()
if cookies := header[setCookieHeaderKey]; len(cookies) > 0 { if cookies := header[setCookieHeaderKey]; len(cookies) > 0 {
s := cookie.Name + "=" // name=?value s := cookie.Name + "=" // name=?value
existingUpdated := false
for i, c := range cookies { for i, c := range cookies {
if strings.HasPrefix(c, s) { 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). // 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 // Probably the cookie is set and then updated in the first session creation
// (e.g. UpdateExpiration, see https://github.com/kataras/iris/issues/1485). // (e.g. UpdateExpiration, see https://github.com/kataras/iris/issues/1485).
cookies[i] = cookie.String() cookies[i] = cookie.String()
header[setCookieHeaderKey] = cookies header[setCookieHeaderKey] = cookies
return false existingUpdated = true
} }
} }
if existingUpdated {
return false // existing one updated.
}
} }
header.Add(setCookieHeaderKey, cookie.String()) header.Add(setCookieHeaderKey, cookie.String())

View File

@ -268,7 +268,7 @@ func (s *Sessions) Destroy(ctx *context.Context) {
ctx.Values().Remove(sessionContextKey) ctx.Values().Remove(sessionContextKey)
ctx.RemoveCookie(s.config.Cookie) ctx.RemoveCookie(s.config.Cookie, s.cookieOptions...)
s.provider.Destroy(cookieValue) s.provider.Destroy(cookieValue)
} }