summaryrefslogtreecommitdiff
path: root/modules/caddyhttp
diff options
context:
space:
mode:
authorFrancis Lavoie <lavofr@gmail.com>2022-07-12 14:16:03 -0400
committerGitHub <noreply@github.com>2022-07-12 12:16:03 -0600
commit53c4d788d4bbc00d396be743a2c0b36482e53c6e (patch)
tree72c9eba7fdd20cefb2cdd17f9ee0f1d09721b59f /modules/caddyhttp
parentd6bc9e0b5c748c999e30051bf04d622dbbb0a156 (diff)
headers: Only replace known placeholders (#4880)
Diffstat (limited to 'modules/caddyhttp')
-rw-r--r--modules/caddyhttp/headers/headers.go20
1 files changed, 10 insertions, 10 deletions
diff --git a/modules/caddyhttp/headers/headers.go b/modules/caddyhttp/headers/headers.go
index f67df92..d523723 100644
--- a/modules/caddyhttp/headers/headers.go
+++ b/modules/caddyhttp/headers/headers.go
@@ -194,27 +194,27 @@ type RespHeaderOps struct {
func (ops HeaderOps) ApplyTo(hdr http.Header, repl *caddy.Replacer) {
// add
for fieldName, vals := range ops.Add {
- fieldName = repl.ReplaceAll(fieldName, "")
+ fieldName = repl.ReplaceKnown(fieldName, "")
for _, v := range vals {
- hdr.Add(fieldName, repl.ReplaceAll(v, ""))
+ hdr.Add(fieldName, repl.ReplaceKnown(v, ""))
}
}
// set
for fieldName, vals := range ops.Set {
- fieldName = repl.ReplaceAll(fieldName, "")
+ fieldName = repl.ReplaceKnown(fieldName, "")
var newVals []string
for i := range vals {
// append to new slice so we don't overwrite
// the original values in ops.Set
- newVals = append(newVals, repl.ReplaceAll(vals[i], ""))
+ newVals = append(newVals, repl.ReplaceKnown(vals[i], ""))
}
hdr.Set(fieldName, strings.Join(newVals, ","))
}
// delete
for _, fieldName := range ops.Delete {
- fieldName = strings.ToLower(repl.ReplaceAll(fieldName, ""))
+ fieldName = strings.ToLower(repl.ReplaceKnown(fieldName, ""))
switch {
case strings.HasPrefix(fieldName, "*") && strings.HasSuffix(fieldName, "*"):
for existingField := range hdr {
@@ -241,13 +241,13 @@ func (ops HeaderOps) ApplyTo(hdr http.Header, repl *caddy.Replacer) {
// replace
for fieldName, replacements := range ops.Replace {
- fieldName = http.CanonicalHeaderKey(repl.ReplaceAll(fieldName, ""))
+ fieldName = http.CanonicalHeaderKey(repl.ReplaceKnown(fieldName, ""))
// all fields...
if fieldName == "*" {
for _, r := range replacements {
- search := repl.ReplaceAll(r.Search, "")
- replace := repl.ReplaceAll(r.Replace, "")
+ search := repl.ReplaceKnown(r.Search, "")
+ replace := repl.ReplaceKnown(r.Replace, "")
for fieldName, vals := range hdr {
for i := range vals {
if r.re != nil {
@@ -263,8 +263,8 @@ func (ops HeaderOps) ApplyTo(hdr http.Header, repl *caddy.Replacer) {
// ...or only with the named field
for _, r := range replacements {
- search := repl.ReplaceAll(r.Search, "")
- replace := repl.ReplaceAll(r.Replace, "")
+ search := repl.ReplaceKnown(r.Search, "")
+ replace := repl.ReplaceKnown(r.Replace, "")
for hdrFieldName, vals := range hdr {
// see issue #4330 for why we don't simply use hdr[fieldName]
if http.CanonicalHeaderKey(hdrFieldName) != fieldName {