mirror of
https://github.com/golang/go
synced 2024-11-22 09:44:40 -07:00
http: do not cache CanonicalHeaderKey
Fixes #1080. R=rsc CC=golang-dev https://golang.org/cl/2158043
This commit is contained in:
parent
5baaa490d6
commit
f7a71c6505
@ -382,29 +382,30 @@ func parseHTTPVersion(vers string) (int, int, bool) {
|
|||||||
return major, minor, true
|
return major, minor, true
|
||||||
}
|
}
|
||||||
|
|
||||||
var cmap = make(map[string]string)
|
|
||||||
|
|
||||||
// CanonicalHeaderKey returns the canonical format of the
|
// CanonicalHeaderKey returns the canonical format of the
|
||||||
// HTTP header key s. The canonicalization converts the first
|
// HTTP header key s. The canonicalization converts the first
|
||||||
// letter and any letter following a hyphen to upper case;
|
// letter and any letter following a hyphen to upper case;
|
||||||
// the rest are converted to lowercase. For example, the
|
// the rest are converted to lowercase. For example, the
|
||||||
// canonical key for "accept-encoding" is "Accept-Encoding".
|
// canonical key for "accept-encoding" is "Accept-Encoding".
|
||||||
func CanonicalHeaderKey(s string) string {
|
func CanonicalHeaderKey(s string) string {
|
||||||
if t, ok := cmap[s]; ok {
|
|
||||||
return t
|
|
||||||
}
|
|
||||||
|
|
||||||
// canonicalize: first letter upper case
|
// canonicalize: first letter upper case
|
||||||
// and upper case after each dash.
|
// and upper case after each dash.
|
||||||
// (Host, User-Agent, If-Modified-Since).
|
// (Host, User-Agent, If-Modified-Since).
|
||||||
// HTTP headers are ASCII only, so no Unicode issues.
|
// HTTP headers are ASCII only, so no Unicode issues.
|
||||||
a := []byte(s)
|
var a []byte
|
||||||
upper := true
|
upper := true
|
||||||
for i, v := range a {
|
for i := 0; i < len(s); i++ {
|
||||||
|
v := s[i]
|
||||||
if upper && 'a' <= v && v <= 'z' {
|
if upper && 'a' <= v && v <= 'z' {
|
||||||
|
if a == nil {
|
||||||
|
a = []byte(s)
|
||||||
|
}
|
||||||
a[i] = v + 'A' - 'a'
|
a[i] = v + 'A' - 'a'
|
||||||
}
|
}
|
||||||
if !upper && 'A' <= v && v <= 'Z' {
|
if !upper && 'A' <= v && v <= 'Z' {
|
||||||
|
if a == nil {
|
||||||
|
a = []byte(s)
|
||||||
|
}
|
||||||
a[i] = v + 'a' - 'A'
|
a[i] = v + 'a' - 'A'
|
||||||
}
|
}
|
||||||
upper = false
|
upper = false
|
||||||
@ -412,9 +413,10 @@ func CanonicalHeaderKey(s string) string {
|
|||||||
upper = true
|
upper = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
t := string(a)
|
if a != nil {
|
||||||
cmap[s] = t
|
return string(a)
|
||||||
return t
|
}
|
||||||
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
type chunkedReader struct {
|
type chunkedReader struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user