if !found {
return nil, errEqualNotFoundInCookie
}
- if !isCookieNameValid(name) {
+ if !isToken(name) {
return nil, errInvalidCookieName
}
value, quoted, found := parseCookieValue(value, true)
return nil, errEqualNotFoundInCookie
}
name = textproto.TrimString(name)
- if !isCookieNameValid(name) {
+ if !isToken(name) {
return nil, errInvalidCookieName
}
value, quoted, ok := parseCookieValue(value, true)
// header (if other fields are set).
// If c is nil or c.Name is invalid, the empty string is returned.
func (c *Cookie) String() string {
- if c == nil || !isCookieNameValid(c.Name) {
+ if c == nil || !isToken(c.Name) {
return ""
}
// extraCookieLength derived from typical length of cookie attributes
if c == nil {
return errors.New("http: nil Cookie")
}
- if !isCookieNameValid(c.Name) {
+ if !isToken(c.Name) {
return errors.New("http: invalid Cookie.Name")
}
if !c.Expires.IsZero() && !validCookieExpires(c.Expires) {
}
name, val, _ := strings.Cut(part, "=")
name = textproto.TrimString(name)
- if !isCookieNameValid(name) {
+ if !isToken(name) {
continue
}
if filter != "" && filter != name {
}
return raw, quoted, true
}
-
-func isCookieNameValid(raw string) bool {
- if raw == "" {
- return false
- }
- return strings.IndexFunc(raw, isNotToken) < 0
-}
return !httpguts.IsTokenRune(r)
}
+// isToken reports whether v is a valid token (https://www.rfc-editor.org/rfc/rfc2616#section-2.2).
+func isToken(v string) bool {
+ // For historical reasons, this function is called ValidHeaderFieldName (see issue #67031).
+ return httpguts.ValidHeaderFieldName(v)
+}
+
// stringContainsCTLByte reports whether s contains any ASCII control character.
func stringContainsCTLByte(s string) bool {
for i := 0; i < len(s); i++ {