summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/headers
diff options
context:
space:
mode:
Diffstat (limited to 'modules/caddyhttp/headers')
-rw-r--r--modules/caddyhttp/headers/headers.go21
1 files changed, 13 insertions, 8 deletions
diff --git a/modules/caddyhttp/headers/headers.go b/modules/caddyhttp/headers/headers.go
index 84dc453..d57b811 100644
--- a/modules/caddyhttp/headers/headers.go
+++ b/modules/caddyhttp/headers/headers.go
@@ -40,20 +40,25 @@ type RespHeaderOps struct {
func (h Headers) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error {
repl := r.Context().Value(caddy.ReplacerCtxKey).(caddy.Replacer)
apply(h.Request, r.Header, repl)
- if h.Response.Deferred || h.Response.Require != nil {
- w = &responseWriterWrapper{
- ResponseWriterWrapper: &caddyhttp.ResponseWriterWrapper{ResponseWriter: w},
- replacer: repl,
- require: h.Response.Require,
- headerOps: h.Response.HeaderOps,
+ if h.Response != nil {
+ if h.Response.Deferred || h.Response.Require != nil {
+ w = &responseWriterWrapper{
+ ResponseWriterWrapper: &caddyhttp.ResponseWriterWrapper{ResponseWriter: w},
+ replacer: repl,
+ require: h.Response.Require,
+ headerOps: h.Response.HeaderOps,
+ }
+ } else {
+ apply(h.Response.HeaderOps, w.Header(), repl)
}
- } else {
- apply(h.Response.HeaderOps, w.Header(), repl)
}
return next.ServeHTTP(w, r)
}
func apply(ops *HeaderOps, hdr http.Header, repl caddy.Replacer) {
+ if ops == nil {
+ return
+ }
for fieldName, vals := range ops.Add {
fieldName = repl.ReplaceAll(fieldName, "")
for _, v := range vals {