mirror of
https://github.com/caddyserver/caddy.git
synced 2024-11-29 04:10:16 +08:00
headers: Support deleting all headers as first op (#5464)
* Delete all existing fields when fieldName is `*` * Rearrange deletion before addition in headers * Revert "Rearrange deletion before addition in headers" This reverts commit 1b50eeeccc92ccd660c7896d8283c7d9e5d1fcb0. * Treat deleting all headers as a special case * Apply suggestions from code review Co-authored-by: Matt Holt <mholt@users.noreply.github.com> --------- Co-authored-by: Matt Holt <mholt@users.noreply.github.com>
This commit is contained in:
parent
f5a13a4ab4
commit
dd86171d67
|
@ -192,6 +192,19 @@ type RespHeaderOps struct {
|
|||
|
||||
// ApplyTo applies ops to hdr using repl.
|
||||
func (ops HeaderOps) ApplyTo(hdr http.Header, repl *caddy.Replacer) {
|
||||
// before manipulating headers in other ways, check if there
|
||||
// is configuration to delete all headers, and do that first
|
||||
// because if a header is to be added, we don't want to delete
|
||||
// it also
|
||||
for _, fieldName := range ops.Delete {
|
||||
fieldName = repl.ReplaceKnown(fieldName, "")
|
||||
if fieldName == "*" {
|
||||
for existingField := range hdr {
|
||||
delete(hdr, existingField)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add
|
||||
for fieldName, vals := range ops.Add {
|
||||
fieldName = repl.ReplaceKnown(fieldName, "")
|
||||
|
@ -215,6 +228,9 @@ func (ops HeaderOps) ApplyTo(hdr http.Header, repl *caddy.Replacer) {
|
|||
// delete
|
||||
for _, fieldName := range ops.Delete {
|
||||
fieldName = strings.ToLower(repl.ReplaceKnown(fieldName, ""))
|
||||
if fieldName == "*" {
|
||||
continue // handled above
|
||||
}
|
||||
switch {
|
||||
case strings.HasPrefix(fieldName, "*") && strings.HasSuffix(fieldName, "*"):
|
||||
for existingField := range hdr {
|
||||
|
|
Loading…
Reference in New Issue
Block a user