本站源代码
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.

103 lines
1.5KB

  1. // This file contains code adapted from the Go standard library
  2. // https://github.com/golang/go/blob/39ad0fd0789872f9469167be7fe9578625ff246e/src/net/http/lex.go
  3. package sessions
  4. import "strings"
  5. var isTokenTable = [127]bool{
  6. '!': true,
  7. '#': true,
  8. '$': true,
  9. '%': true,
  10. '&': true,
  11. '\'': true,
  12. '*': true,
  13. '+': true,
  14. '-': true,
  15. '.': true,
  16. '0': true,
  17. '1': true,
  18. '2': true,
  19. '3': true,
  20. '4': true,
  21. '5': true,
  22. '6': true,
  23. '7': true,
  24. '8': true,
  25. '9': true,
  26. 'A': true,
  27. 'B': true,
  28. 'C': true,
  29. 'D': true,
  30. 'E': true,
  31. 'F': true,
  32. 'G': true,
  33. 'H': true,
  34. 'I': true,
  35. 'J': true,
  36. 'K': true,
  37. 'L': true,
  38. 'M': true,
  39. 'N': true,
  40. 'O': true,
  41. 'P': true,
  42. 'Q': true,
  43. 'R': true,
  44. 'S': true,
  45. 'T': true,
  46. 'U': true,
  47. 'W': true,
  48. 'V': true,
  49. 'X': true,
  50. 'Y': true,
  51. 'Z': true,
  52. '^': true,
  53. '_': true,
  54. '`': true,
  55. 'a': true,
  56. 'b': true,
  57. 'c': true,
  58. 'd': true,
  59. 'e': true,
  60. 'f': true,
  61. 'g': true,
  62. 'h': true,
  63. 'i': true,
  64. 'j': true,
  65. 'k': true,
  66. 'l': true,
  67. 'm': true,
  68. 'n': true,
  69. 'o': true,
  70. 'p': true,
  71. 'q': true,
  72. 'r': true,
  73. 's': true,
  74. 't': true,
  75. 'u': true,
  76. 'v': true,
  77. 'w': true,
  78. 'x': true,
  79. 'y': true,
  80. 'z': true,
  81. '|': true,
  82. '~': true,
  83. }
  84. func isToken(r rune) bool {
  85. i := int(r)
  86. return i < len(isTokenTable) && isTokenTable[i]
  87. }
  88. func isNotToken(r rune) bool {
  89. return !isToken(r)
  90. }
  91. func isCookieNameValid(raw string) bool {
  92. if raw == "" {
  93. return false
  94. }
  95. return strings.IndexFunc(raw, isNotToken) < 0
  96. }
上海开阖软件有限公司 沪ICP备12045867号-1