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.
 
 
 

89 lines
1.7 KiB

  1. // Copyright 2014 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package http2
  5. import (
  6. "net/http"
  7. "strings"
  8. "sync"
  9. )
  10. var (
  11. commonBuildOnce sync.Once
  12. commonLowerHeader map[string]string // Go-Canonical-Case -> lower-case
  13. commonCanonHeader map[string]string // lower-case -> Go-Canonical-Case
  14. )
  15. func buildCommonHeaderMapsOnce() {
  16. commonBuildOnce.Do(buildCommonHeaderMaps)
  17. }
  18. func buildCommonHeaderMaps() {
  19. common := []string{
  20. "accept",
  21. "accept-charset",
  22. "accept-encoding",
  23. "accept-language",
  24. "accept-ranges",
  25. "age",
  26. "access-control-allow-origin",
  27. "allow",
  28. "authorization",
  29. "cache-control",
  30. "content-disposition",
  31. "content-encoding",
  32. "content-language",
  33. "content-length",
  34. "content-location",
  35. "content-range",
  36. "content-type",
  37. "cookie",
  38. "date",
  39. "etag",
  40. "expect",
  41. "expires",
  42. "from",
  43. "host",
  44. "if-match",
  45. "if-modified-since",
  46. "if-none-match",
  47. "if-unmodified-since",
  48. "last-modified",
  49. "link",
  50. "location",
  51. "max-forwards",
  52. "proxy-authenticate",
  53. "proxy-authorization",
  54. "range",
  55. "referer",
  56. "refresh",
  57. "retry-after",
  58. "server",
  59. "set-cookie",
  60. "strict-transport-security",
  61. "trailer",
  62. "transfer-encoding",
  63. "user-agent",
  64. "vary",
  65. "via",
  66. "www-authenticate",
  67. }
  68. commonLowerHeader = make(map[string]string, len(common))
  69. commonCanonHeader = make(map[string]string, len(common))
  70. for _, v := range common {
  71. chk := http.CanonicalHeaderKey(v)
  72. commonLowerHeader[chk] = v
  73. commonCanonHeader[v] = chk
  74. }
  75. }
  76. func lowerHeader(v string) string {
  77. buildCommonHeaderMapsOnce()
  78. if s, ok := commonLowerHeader[v]; ok {
  79. return s
  80. }
  81. return strings.ToLower(v)
  82. }