forked from ebhomengo/niki
1
0
Fork 0
niki/vendor/golang.org/x/net/http2/headermap.go

191 lines
2.2 KiB
Go
Raw Normal View History

2024-02-18 10:42:21 +00:00
// Copyright 2014 The Go Authors. All rights reserved.
2024-02-18 10:42:21 +00:00
// Use of this source code is governed by a BSD-style
2024-02-18 10:42:21 +00:00
// license that can be found in the LICENSE file.
package http2
import (
"net/http"
"sync"
)
var (
commonBuildOnce sync.Once
2024-02-18 10:42:21 +00:00
commonLowerHeader map[string]string // Go-Canonical-Case -> lower-case
2024-02-18 10:42:21 +00:00
commonCanonHeader map[string]string // lower-case -> Go-Canonical-Case
2024-02-18 10:42:21 +00:00
)
func buildCommonHeaderMapsOnce() {
2024-02-18 10:42:21 +00:00
commonBuildOnce.Do(buildCommonHeaderMaps)
2024-02-18 10:42:21 +00:00
}
func buildCommonHeaderMaps() {
2024-02-18 10:42:21 +00:00
common := []string{
2024-02-18 10:42:21 +00:00
"accept",
2024-02-18 10:42:21 +00:00
"accept-charset",
2024-02-18 10:42:21 +00:00
"accept-encoding",
2024-02-18 10:42:21 +00:00
"accept-language",
2024-02-18 10:42:21 +00:00
"accept-ranges",
2024-02-18 10:42:21 +00:00
"age",
2024-02-18 10:42:21 +00:00
"access-control-allow-credentials",
2024-02-18 10:42:21 +00:00
"access-control-allow-headers",
2024-02-18 10:42:21 +00:00
"access-control-allow-methods",
2024-02-18 10:42:21 +00:00
"access-control-allow-origin",
2024-02-18 10:42:21 +00:00
"access-control-expose-headers",
2024-02-18 10:42:21 +00:00
"access-control-max-age",
2024-02-18 10:42:21 +00:00
"access-control-request-headers",
2024-02-18 10:42:21 +00:00
"access-control-request-method",
2024-02-18 10:42:21 +00:00
"allow",
2024-02-18 10:42:21 +00:00
"authorization",
2024-02-18 10:42:21 +00:00
"cache-control",
2024-02-18 10:42:21 +00:00
"content-disposition",
2024-02-18 10:42:21 +00:00
"content-encoding",
2024-02-18 10:42:21 +00:00
"content-language",
2024-02-18 10:42:21 +00:00
"content-length",
2024-02-18 10:42:21 +00:00
"content-location",
2024-02-18 10:42:21 +00:00
"content-range",
2024-02-18 10:42:21 +00:00
"content-type",
2024-02-18 10:42:21 +00:00
"cookie",
2024-02-18 10:42:21 +00:00
"date",
2024-02-18 10:42:21 +00:00
"etag",
2024-02-18 10:42:21 +00:00
"expect",
2024-02-18 10:42:21 +00:00
"expires",
2024-02-18 10:42:21 +00:00
"from",
2024-02-18 10:42:21 +00:00
"host",
2024-02-18 10:42:21 +00:00
"if-match",
2024-02-18 10:42:21 +00:00
"if-modified-since",
2024-02-18 10:42:21 +00:00
"if-none-match",
2024-02-18 10:42:21 +00:00
"if-unmodified-since",
2024-02-18 10:42:21 +00:00
"last-modified",
2024-02-18 10:42:21 +00:00
"link",
2024-02-18 10:42:21 +00:00
"location",
2024-02-18 10:42:21 +00:00
"max-forwards",
2024-02-18 10:42:21 +00:00
"origin",
2024-02-18 10:42:21 +00:00
"proxy-authenticate",
2024-02-18 10:42:21 +00:00
"proxy-authorization",
2024-02-18 10:42:21 +00:00
"range",
2024-02-18 10:42:21 +00:00
"referer",
2024-02-18 10:42:21 +00:00
"refresh",
2024-02-18 10:42:21 +00:00
"retry-after",
2024-02-18 10:42:21 +00:00
"server",
2024-02-18 10:42:21 +00:00
"set-cookie",
2024-02-18 10:42:21 +00:00
"strict-transport-security",
2024-02-18 10:42:21 +00:00
"trailer",
2024-02-18 10:42:21 +00:00
"transfer-encoding",
2024-02-18 10:42:21 +00:00
"user-agent",
2024-02-18 10:42:21 +00:00
"vary",
2024-02-18 10:42:21 +00:00
"via",
2024-02-18 10:42:21 +00:00
"www-authenticate",
2024-02-18 10:42:21 +00:00
"x-forwarded-for",
2024-02-18 10:42:21 +00:00
"x-forwarded-proto",
}
2024-02-18 10:42:21 +00:00
commonLowerHeader = make(map[string]string, len(common))
2024-02-18 10:42:21 +00:00
commonCanonHeader = make(map[string]string, len(common))
2024-02-18 10:42:21 +00:00
for _, v := range common {
2024-02-18 10:42:21 +00:00
chk := http.CanonicalHeaderKey(v)
2024-02-18 10:42:21 +00:00
commonLowerHeader[chk] = v
2024-02-18 10:42:21 +00:00
commonCanonHeader[v] = chk
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
}
func lowerHeader(v string) (lower string, ascii bool) {
2024-02-18 10:42:21 +00:00
buildCommonHeaderMapsOnce()
2024-02-18 10:42:21 +00:00
if s, ok := commonLowerHeader[v]; ok {
2024-02-18 10:42:21 +00:00
return s, true
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
return asciiToLower(v)
2024-02-18 10:42:21 +00:00
}
func canonicalHeader(v string) string {
2024-02-18 10:42:21 +00:00
buildCommonHeaderMapsOnce()
2024-02-18 10:42:21 +00:00
if s, ok := commonCanonHeader[v]; ok {
2024-02-18 10:42:21 +00:00
return s
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
return http.CanonicalHeaderKey(v)
2024-02-18 10:42:21 +00:00
}