update cookie.go to be aligned with quality standars
@@ -52,7 +52,7 @@ func RemoveCookie(ctx context.Context, config Config) {
cookie.MaxAge = -1
cookie.Value = ""
cookie.Path = "/"
- cookie.Domain = FormatCookieDomain(ctx, config.DisableSubdomainPersistence)
+ cookie.Domain = formatCookieDomain(ctx, config.DisableSubdomainPersistence)
AddCookie(ctx, cookie, config.AllowReclaim)
@@ -92,14 +92,19 @@ func IsValidCookieDomain(domain string) bool {
return true
}
-func FormatCookieDomain(ctx context.Context, DisableSubdomainPersistence bool) string {
- if !DisableSubdomainPersistence {
+func formatCookieDomain(ctx context.Context, disableSubdomainPersistence bool) string {
+ if disableSubdomainPersistence {
+ return ""
+ }
requestDomain := ctx.Host()
if portIdx := strings.IndexByte(requestDomain, ':'); portIdx > 0 {
requestDomain = requestDomain[0:portIdx]
}
- if IsValidCookieDomain(requestDomain) {
+
+ if !IsValidCookieDomain(requestDomain) {
+ return ""
+ }
// RFC2109, we allow level 1 subdomains, but no further
// if we have localhost.com , we want the localhost.cos.
@@ -122,6 +127,3 @@ func FormatCookieDomain(ctx context.Context, DisableSubdomainPersistence bool) s
// finally set the .localhost.com (for(1-level) || .mysubdomain.localhost.com (for 2-level subdomain allow)
return "." + requestDomain // . to allow persistence
}
- }
- return ""
-}
