1
0
mirror of https://github.com/oauth2-proxy/oauth2-proxy.git synced 2025-11-29 22:48:19 +02:00

Some code improvements

* Remove shadowing of predeclared identifier: new.
* strings.ReplaceAll instead of strings.Replace with -1.
* Change strings.ToLower comparison to strings.EqualFold.
* Rewrite if-else-if-else chain as a switch.
This commit is contained in:
Kirill Motkov
2019-10-09 11:33:45 +03:00
parent 63da5c64db
commit e64e6fa514
4 changed files with 11 additions and 10 deletions

View File

@@ -136,18 +136,18 @@ func splitCookie(c *http.Cookie) []*http.Cookie {
valueBytes := []byte(c.Value)
count := 0
for len(valueBytes) > 0 {
new := copyCookie(c)
new.Name = fmt.Sprintf("%s_%d", c.Name, count)
newCookie := copyCookie(c)
newCookie.Name = fmt.Sprintf("%s_%d", c.Name, count)
count++
if len(valueBytes) < maxCookieLength {
new.Value = string(valueBytes)
newCookie.Value = string(valueBytes)
valueBytes = []byte{}
} else {
newValue := valueBytes[:maxCookieLength]
valueBytes = valueBytes[maxCookieLength:]
new.Value = string(newValue)
newCookie.Value = string(newValue)
}
cookies = append(cookies, new)
cookies = append(cookies, newCookie)
}
return cookies
}