summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--caddytest/integration/caddyfile_adapt/header.txt12
-rw-r--r--modules/caddyhttp/headers/caddyfile.go24
2 files changed, 29 insertions, 7 deletions
diff --git a/caddytest/integration/caddyfile_adapt/header.txt b/caddytest/integration/caddyfile_adapt/header.txt
index 34a044d..95c1474 100644
--- a/caddytest/integration/caddyfile_adapt/header.txt
+++ b/caddytest/integration/caddyfile_adapt/header.txt
@@ -17,6 +17,7 @@
+Link "Foo"
+Link "Bar"
}
+ header >Set Defer
}
----------
{
@@ -136,6 +137,17 @@
]
}
}
+ },
+ {
+ "handler": "headers",
+ "response": {
+ "deferred": true,
+ "set": {
+ "Set": [
+ "Defer"
+ ]
+ }
+ }
}
]
}
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)