headers: Allow nil HeaderOps (fix #6893)
Some checks failed
Lint / lint (macos-14, mac) (push) Waiting to run
Lint / lint (windows-latest, windows) (push) Waiting to run
Tests / test (./cmd/caddy/caddy, ~1.24.1, ubuntu-latest, 0, 1.24, linux) (push) Failing after 1m34s
Tests / test (s390x on IBM Z) (push) Has been skipped
Tests / goreleaser-check (push) Has been skipped
Lint / lint (ubuntu-latest, linux) (push) Successful in 1m54s
Lint / govulncheck (push) Successful in 1m14s
Tests / test (./cmd/caddy/caddy, ~1.24.1, macos-14, 0, 1.24, mac) (push) Has been cancelled
Tests / test (./cmd/caddy/caddy.exe, ~1.24.1, windows-latest, True, 1.24, windows) (push) Has been cancelled

This commit is contained in:
Matthew Holt 2025-03-11 08:52:15 -06:00
parent 39262f8663
commit af2d33afbb
No known key found for this signature in database
GPG Key ID: 2A349DD577D586A5

View File

@ -78,7 +78,7 @@ func (h Handler) Validate() error {
return err return err
} }
} }
if h.Response != nil { if h.Response != nil && h.Response.HeaderOps != nil {
err := h.Response.validate() err := h.Response.validate()
if err != nil { if err != nil {
return err return err
@ -133,6 +133,9 @@ type HeaderOps struct {
// Provision sets up the header operations. // Provision sets up the header operations.
func (ops *HeaderOps) Provision(_ caddy.Context) error { func (ops *HeaderOps) Provision(_ caddy.Context) error {
if ops == nil {
return nil // it's possible no ops are configured; fix #6893
}
for fieldName, replacements := range ops.Replace { for fieldName, replacements := range ops.Replace {
for i, r := range replacements { for i, r := range replacements {
if r.SearchRegexp == "" { if r.SearchRegexp == "" {