Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(context.CookieAllowReclaim): Fix the issue with the context.Cooki… #2136

Merged
merged 1 commit into from
May 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 5 additions & 21 deletions context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -5518,29 +5518,13 @@ func CookieAllowReclaim(cookieNames ...string) CookieOption {
// perform upsert on request cookies or is it too much and not worth the cost?
ctx.Request().AddCookie(c)
case OpCookieDel:
header := ctx.Request().Header

if cookiesLine := header.Get("Cookie"); cookiesLine != "" {
if cookies := strings.Split(cookiesLine, "; "); len(cookies) > 1 {
// more than one cookie here.
// 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
cookies := ctx.Request().Cookies()
ctx.Request().Header.Del("Cookie")
for i, v := range cookies {
if v.Name != c.Name {
ctx.Request().AddCookie(cookies[i])
}
}

header.Del("Cookie")
}
}
}
Expand Down