headermap.go 1.6 KB

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