mirror of
https://github.com/caddyserver/caddy.git
synced 2026-08-04 06:53:36 +00:00
caddyhttp: use canonical header key casing to avoid re-canonicalization (#7911)
Header.Get/Set re-canonicalize and allocate whenever the passed key isn't already in canonical MIME header form. Sec-WebSocket-Key, WWW-Authenticate, and content-type all miss the fast path; switch to their canonical forms (Sec-Websocket-Key, Www-Authenticate, Content-Type). Enable the canonicalheader linter to catch future regressions, excluded in test files since those already use non-canonical casing in several places without a perf-sensitive path behind them.
This commit is contained in:
parent
c96bca1269
commit
3be8dabc89
4 changed files with 7 additions and 3 deletions
|
|
@ -19,6 +19,7 @@ linters:
|
|||
- asciicheck
|
||||
- bidichk
|
||||
- bodyclose
|
||||
- canonicalheader
|
||||
- decorder
|
||||
- dogsled
|
||||
- dupl
|
||||
|
|
@ -97,6 +98,9 @@ linters:
|
|||
- linters:
|
||||
- errcheck
|
||||
path: _test\.go
|
||||
- linters:
|
||||
- canonicalheader
|
||||
path: _test\.go
|
||||
paths:
|
||||
- third_party$
|
||||
- builtin$
|
||||
|
|
|
|||
|
|
@ -212,7 +212,7 @@ func (hba HTTPBasicAuth) promptForCredentials(w http.ResponseWriter, err error)
|
|||
if realm == "" {
|
||||
realm = "restricted"
|
||||
}
|
||||
w.Header().Set("WWW-Authenticate", fmt.Sprintf(`Basic realm="%s"`, realm))
|
||||
w.Header().Set("Www-Authenticate", fmt.Sprintf(`Basic realm="%s"`, realm))
|
||||
return User{}, false, err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -499,10 +499,10 @@ func hasVaryValue(hdr http.Header, target string) bool {
|
|||
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html.
|
||||
func AcceptedEncodings(r *http.Request, preferredOrder []string) []string {
|
||||
acceptEncHeader := r.Header.Get("Accept-Encoding")
|
||||
websocketKey := r.Header.Get("Sec-WebSocket-Key")
|
||||
if acceptEncHeader == "" {
|
||||
return []string{}
|
||||
}
|
||||
websocketKey := r.Header.Get("Sec-Websocket-Key")
|
||||
|
||||
prefs := []encodingPreference{}
|
||||
|
||||
|
|
|
|||
|
|
@ -1368,7 +1368,7 @@ func (m MatchProtocol) Match(r *http.Request) bool {
|
|||
func (m MatchProtocol) MatchWithError(r *http.Request) (bool, error) {
|
||||
switch string(m) {
|
||||
case "grpc":
|
||||
return strings.HasPrefix(r.Header.Get("content-type"), "application/grpc"), nil
|
||||
return strings.HasPrefix(r.Header.Get("Content-Type"), "application/grpc"), nil
|
||||
case "https":
|
||||
return r.TLS != nil, nil
|
||||
case "http":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue