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 5package http2 6 7import ( 8 "net/http" 9 "sync" 10) 11 12var ( 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 18func buildCommonHeaderMapsOnce() { 19 commonBuildOnce.Do(buildCommonHeaderMaps) 20} 21 22func 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 81func lowerHeader(v string) (lower string, ascii bool) { 82 buildCommonHeaderMapsOnce() 83 if s, ok := commonLowerHeader[v]; ok { 84 return s, true 85 } 86 return asciiToLower(v) 87} 88