mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
fix(context.CookieAllowReclaim): Fix the issue with the context.CookieAllowReclaim method not working as expected when deleting cookies (#2136)
When deleting cookies, if the cookie is the first element and there is no semicolon before the string, it prevents the matching of this cookie. Closes #2134
This commit is contained in:
parent
67736edc15
commit
e05582b8e0
|
@ -5518,29 +5518,13 @@ func CookieAllowReclaim(cookieNames ...string) CookieOption {
|
||||||
// perform upsert on request cookies or is it too much and not worth the cost?
|
// perform upsert on request cookies or is it too much and not worth the cost?
|
||||||
ctx.Request().AddCookie(c)
|
ctx.Request().AddCookie(c)
|
||||||
case OpCookieDel:
|
case OpCookieDel:
|
||||||
header := ctx.Request().Header
|
cookies := ctx.Request().Cookies()
|
||||||
|
ctx.Request().Header.Del("Cookie")
|
||||||
if cookiesLine := header.Get("Cookie"); cookiesLine != "" {
|
for i, v := range cookies {
|
||||||
if cookies := strings.Split(cookiesLine, "; "); len(cookies) > 1 {
|
if v.Name != c.Name {
|
||||||
// more than one cookie here.
|
ctx.Request().AddCookie(cookies[i])
|
||||||
// select that one and remove it.
|
|
||||||
name := sanitizeCookieName(c.Name)
|
|
||||||
|
|
||||||
for _, nameValue := range cookies {
|
|
||||||
if strings.HasPrefix(nameValue, name) {
|
|
||||||
cookiesLine = strings.Replace(cookiesLine, "; "+nameValue, "", 1)
|
|
||||||
// current cookiesLine: myapp_session_id=5ccf4e89-8d0e-4ed6-9f4c-6746d7c5e2ee; key1=value1
|
|
||||||
// found nameValue: key1=value1
|
|
||||||
// new cookiesLine: myapp_session_id=5ccf4e89-8d0e-4ed6-9f4c-6746d7c5e2ee
|
|
||||||
header.Set("Cookie", cookiesLine)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
header.Del("Cookie")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user