aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/golang.org/x/net/http2/headermap.go
blob: c3ff3fa1c78c0870021a4fe343511fc8ce2e09da (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package http2

import (
    "net/http"
    "strings"
    "sync"
)

var (
    commonBuildOnce   sync.Once
    commonLowerHeader map[string]string // Go-Canonical-Case -> lower-case
    commonCanonHeader map[string]string // lower-case -> Go-Canonical-Case
)

func buildCommonHeaderMapsOnce() {
    commonBuildOnce.Do(buildCommonHeaderMaps)
}

func buildCommonHeaderMaps() {
    common := []string{
        "accept",
        "accept-charset",
        "accept-encoding",
        "accept-language",
        "accept-ranges",
        "age",
        "access-control-allow-origin",
        "allow",
        "authorization",
        "cache-control",
        "content-disposition",
        "content-encoding",
        "content-language",
        "content-length",
        "content-location",
        "content-range",
        "content-type",
        "cookie",
        "date",
        "etag",
        "expect",
        "expires",
        "from",
        "host",
        "if-match",
        "if-modified-since",
        "if-none-match",
        "if-unmodified-since",
        "last-modified",
        "link",
        "location",
        "max-forwards",
        "proxy-authenticate",
        "proxy-authorization",
        "range",
        "referer",
        "refresh",
        "retry-after",
        "server",
        "set-cookie",
        "strict-transport-security",
        "trailer",
        "transfer-encoding",
        "user-agent",
        "vary",
        "via",
        "www-authenticate",
    }
    commonLowerHeader = make(map[string]string, len(common))
    commonCanonHeader = make(map[string]string, len(common))
    for _, v := range common {
        chk := http.CanonicalHeaderKey(v)
        commonLowerHeader[chk] = v
        commonCanonHeader[v] = chk
    }
}

func lowerHeader(v string) string {
    buildCommonHeaderMapsOnce()
    if s, ok := commonLowerHeader[v]; ok {
        return s
    }
    return strings.ToLower(v)
}