headermap.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. )
  9. var (
  10. commonLowerHeader = map[string]string{} // Go-Canonical-Case -> lower-case
  11. commonCanonHeader = map[string]string{} // lower-case -> Go-Canonical-Case
  12. )
  13. func init() {
  14. for _, v := range []string{
  15. "accept",
  16. "accept-charset",
  17. "accept-encoding",
  18. "accept-language",
  19. "accept-ranges",
  20. "age",
  21. "access-control-allow-origin",
  22. "allow",
  23. "authorization",
  24. "cache-control",
  25. "content-disposition",
  26. "content-encoding",
  27. "content-language",
  28. "content-length",
  29. "content-location",
  30. "content-range",
  31. "content-type",
  32. "cookie",
  33. "date",
  34. "etag",
  35. "expect",
  36. "expires",
  37. "from",
  38. "host",
  39. "if-match",
  40. "if-modified-since",
  41. "if-none-match",
  42. "if-unmodified-since",
  43. "last-modified",
  44. "link",
  45. "location",
  46. "max-forwards",
  47. "proxy-authenticate",
  48. "proxy-authorization",
  49. "range",
  50. "referer",
  51. "refresh",
  52. "retry-after",
  53. "server",
  54. "set-cookie",
  55. "strict-transport-security",
  56. "trailer",
  57. "transfer-encoding",
  58. "user-agent",
  59. "vary",
  60. "via",
  61. "www-authenticate",
  62. } {
  63. chk := http.CanonicalHeaderKey(v)
  64. commonLowerHeader[chk] = v
  65. commonCanonHeader[v] = chk
  66. }
  67. }
  68. func lowerHeader(v string) string {
  69. if s, ok := commonLowerHeader[v]; ok {
  70. return s
  71. }
  72. return strings.ToLower(v)
  73. }