mirror of https://github.com/gorilla/sessions
Mirror of https://github.com/gorilla/sessions
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
1.5 KiB
102 lines
1.5 KiB
// This file contains code adapted from the Go standard library |
|
// https://github.com/golang/go/blob/39ad0fd0789872f9469167be7fe9578625ff246e/src/net/http/lex.go |
|
|
|
package sessions |
|
|
|
import "strings" |
|
|
|
var isTokenTable = [127]bool{ |
|
'!': true, |
|
'#': true, |
|
'$': true, |
|
'%': true, |
|
'&': true, |
|
'\'': true, |
|
'*': true, |
|
'+': true, |
|
'-': true, |
|
'.': true, |
|
'0': true, |
|
'1': true, |
|
'2': true, |
|
'3': true, |
|
'4': true, |
|
'5': true, |
|
'6': true, |
|
'7': true, |
|
'8': true, |
|
'9': true, |
|
'A': true, |
|
'B': true, |
|
'C': true, |
|
'D': true, |
|
'E': true, |
|
'F': true, |
|
'G': true, |
|
'H': true, |
|
'I': true, |
|
'J': true, |
|
'K': true, |
|
'L': true, |
|
'M': true, |
|
'N': true, |
|
'O': true, |
|
'P': true, |
|
'Q': true, |
|
'R': true, |
|
'S': true, |
|
'T': true, |
|
'U': true, |
|
'W': true, |
|
'V': true, |
|
'X': true, |
|
'Y': true, |
|
'Z': true, |
|
'^': true, |
|
'_': true, |
|
'`': true, |
|
'a': true, |
|
'b': true, |
|
'c': true, |
|
'd': true, |
|
'e': true, |
|
'f': true, |
|
'g': true, |
|
'h': true, |
|
'i': true, |
|
'j': true, |
|
'k': true, |
|
'l': true, |
|
'm': true, |
|
'n': true, |
|
'o': true, |
|
'p': true, |
|
'q': true, |
|
'r': true, |
|
's': true, |
|
't': true, |
|
'u': true, |
|
'v': true, |
|
'w': true, |
|
'x': true, |
|
'y': true, |
|
'z': true, |
|
'|': true, |
|
'~': true, |
|
} |
|
|
|
func isToken(r rune) bool { |
|
i := int(r) |
|
return i < len(isTokenTable) && isTokenTable[i] |
|
} |
|
|
|
func isNotToken(r rune) bool { |
|
return !isToken(r) |
|
} |
|
|
|
func isCookieNameValid(raw string) bool { |
|
if raw == "" { |
|
return false |
|
} |
|
return strings.IndexFunc(raw, isNotToken) < 0 |
|
}
|
|
|