1
0
mirror of https://github.com/golang/go synced 2024-11-22 04:24:39 -07:00

http: do not cache CanonicalHeaderKey

Fixes #1080.

R=rsc
CC=golang-dev
https://golang.org/cl/2158043
This commit is contained in:
Jukka-Pekka Kekkonen 2010-09-08 10:20:21 -04:00 committed by Russ Cox
parent 5baaa490d6
commit f7a71c6505

View File

@ -382,29 +382,30 @@ func parseHTTPVersion(vers string) (int, int, bool) {
return major, minor, true
}
var cmap = make(map[string]string)
// CanonicalHeaderKey returns the canonical format of the
// HTTP header key s. The canonicalization converts the first
// letter and any letter following a hyphen to upper case;
// the rest are converted to lowercase. For example, the
// canonical key for "accept-encoding" is "Accept-Encoding".
func CanonicalHeaderKey(s string) string {
if t, ok := cmap[s]; ok {
return t
}
// canonicalize: first letter upper case
// and upper case after each dash.
// (Host, User-Agent, If-Modified-Since).
// HTTP headers are ASCII only, so no Unicode issues.
a := []byte(s)
var a []byte
upper := true
for i, v := range a {
for i := 0; i < len(s); i++ {
v := s[i]
if upper && 'a' <= v && v <= 'z' {
if a == nil {
a = []byte(s)
}
a[i] = v + 'A' - 'a'
}
if !upper && 'A' <= v && v <= 'Z' {
if a == nil {
a = []byte(s)
}
a[i] = v + 'a' - 'A'
}
upper = false
@ -412,9 +413,10 @@ func CanonicalHeaderKey(s string) string {
upper = true
}
}
t := string(a)
cmap[s] = t
return t
if a != nil {
return string(a)
}
return s
}
type chunkedReader struct {