diff options
author | Francis Lavoie <lavofr@gmail.com> | 2023-05-16 01:18:13 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-16 01:18:13 -0400 |
commit | e8352aef38642c20ff528836b6581094f087eb99 (patch) | |
tree | 804017249d89334cf7d1fe797589a22b35962af1 /modules | |
parent | 36546cd8b92d683942cda5cf5f9d8f58c08ae9b4 (diff) |
headers: Add > Caddyfile shortcut for enabling defer (#5535)
Diffstat (limited to 'modules')
-rw-r--r-- | modules/caddyhttp/headers/caddyfile.go | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/modules/caddyhttp/headers/caddyfile.go b/modules/caddyhttp/headers/caddyfile.go index a6bec95..d7e644c 100644 --- a/modules/caddyhttp/headers/caddyfile.go +++ b/modules/caddyhttp/headers/caddyfile.go @@ -32,19 +32,20 @@ func init() { // parseCaddyfile sets up the handler for response headers from // Caddyfile tokens. Syntax: // -// header [<matcher>] [[+|-|?]<field> [<value|regexp>] [<replacement>]] { -// [+]<field> [<value|regexp> [<replacement>]] -// ?<field> <default_value> -// -<field> -// [defer] +// header [<matcher>] [[+|-|?|>]<field> [<value|regexp>] [<replacement>]] { +// [+]<field> [<value|regexp> [<replacement>]] +// ?<field> <default_value> +// -<field> +// ><field> +// [defer] // } // // Either a block can be opened or a single header field can be configured // in the first line, but not both in the same directive. Header operations // are deferred to write-time if any headers are being deleted or if the // 'defer' subdirective is used. + appends a header value, - deletes a field, -// and ? conditionally sets a value only if the header field is not already -// set. +// ? conditionally sets a value only if the header field is not already set, +// and > sets a field with defer enabled. func parseCaddyfile(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error) { if !h.Next() { return nil, h.ArgErr() @@ -258,6 +259,15 @@ func applyHeaderOp(ops *HeaderOps, respHeaderOps *RespHeaderOps, field, value, r }, ) + case strings.HasPrefix(field, ">"): // set (overwrite) with defer + if ops.Set == nil { + ops.Set = make(http.Header) + } + ops.Set.Set(field[1:], value) + if respHeaderOps != nil { + respHeaderOps.Deferred = true + } + default: // set (overwrite) if ops.Set == nil { ops.Set = make(http.Header) |