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