Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 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 | |
| 5 | package http2 |
| 6 | |
| 7 | import ( |
| 8 | "net/http" |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 9 | "sync" |
| 10 | ) |
| 11 | |
| 12 | var ( |
| 13 | commonBuildOnce sync.Once |
| 14 | commonLowerHeader map[string]string // Go-Canonical-Case -> lower-case |
| 15 | commonCanonHeader map[string]string // lower-case -> Go-Canonical-Case |
| 16 | ) |
| 17 | |
| 18 | func buildCommonHeaderMapsOnce() { |
| 19 | commonBuildOnce.Do(buildCommonHeaderMaps) |
| 20 | } |
| 21 | |
| 22 | func buildCommonHeaderMaps() { |
| 23 | common := []string{ |
| 24 | "accept", |
| 25 | "accept-charset", |
| 26 | "accept-encoding", |
| 27 | "accept-language", |
| 28 | "accept-ranges", |
| 29 | "age", |
| 30 | "access-control-allow-origin", |
| 31 | "allow", |
| 32 | "authorization", |
| 33 | "cache-control", |
| 34 | "content-disposition", |
| 35 | "content-encoding", |
| 36 | "content-language", |
| 37 | "content-length", |
| 38 | "content-location", |
| 39 | "content-range", |
| 40 | "content-type", |
| 41 | "cookie", |
| 42 | "date", |
| 43 | "etag", |
| 44 | "expect", |
| 45 | "expires", |
| 46 | "from", |
| 47 | "host", |
| 48 | "if-match", |
| 49 | "if-modified-since", |
| 50 | "if-none-match", |
| 51 | "if-unmodified-since", |
| 52 | "last-modified", |
| 53 | "link", |
| 54 | "location", |
| 55 | "max-forwards", |
| 56 | "proxy-authenticate", |
| 57 | "proxy-authorization", |
| 58 | "range", |
| 59 | "referer", |
| 60 | "refresh", |
| 61 | "retry-after", |
| 62 | "server", |
| 63 | "set-cookie", |
| 64 | "strict-transport-security", |
| 65 | "trailer", |
| 66 | "transfer-encoding", |
| 67 | "user-agent", |
| 68 | "vary", |
| 69 | "via", |
| 70 | "www-authenticate", |
| 71 | } |
| 72 | commonLowerHeader = make(map[string]string, len(common)) |
| 73 | commonCanonHeader = make(map[string]string, len(common)) |
| 74 | for _, v := range common { |
| 75 | chk := http.CanonicalHeaderKey(v) |
| 76 | commonLowerHeader[chk] = v |
| 77 | commonCanonHeader[v] = chk |
| 78 | } |
| 79 | } |
| 80 | |
khenaidoo | 2672188 | 2021-08-11 17:42:52 -0400 | [diff] [blame] | 81 | func lowerHeader(v string) (lower string, ascii bool) { |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 82 | buildCommonHeaderMapsOnce() |
| 83 | if s, ok := commonLowerHeader[v]; ok { |
khenaidoo | 2672188 | 2021-08-11 17:42:52 -0400 | [diff] [blame] | 84 | return s, true |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 85 | } |
khenaidoo | 2672188 | 2021-08-11 17:42:52 -0400 | [diff] [blame] | 86 | return asciiToLower(v) |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 87 | } |