caddyhttp: Canonicalize header field names (#5176)

This commit is contained in:
Alexander Graf 2022-10-29 22:35:44 +02:00 committed by GitHub
parent 1fa4cb7ba1
commit 087f126cf4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -21,6 +21,7 @@ import (
"fmt" "fmt"
"io" "io"
"net/http" "net/http"
"net/textproto"
"os" "os"
"strconv" "strconv"
"strings" "strings"
@ -193,7 +194,7 @@ func (s StaticResponse) ServeHTTP(w http.ResponseWriter, r *http.Request, next H
// set all headers // set all headers
for field, vals := range s.Headers { for field, vals := range s.Headers {
field = repl.ReplaceAll(field, "") field = textproto.CanonicalMIMEHeaderKey(repl.ReplaceAll(field, ""))
newVals := make([]string, len(vals)) newVals := make([]string, len(vals))
for i := range vals { for i := range vals {
newVals[i] = repl.ReplaceAll(vals[i], "") newVals[i] = repl.ReplaceAll(vals[i], "")