summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/vars.go
diff options
context:
space:
mode:
authorFrancis Lavoie <lavofr@gmail.com>2022-07-28 17:19:48 -0400
committerGitHub <noreply@github.com>2022-07-28 15:19:48 -0600
commitff2ba6de8a312813140b5db24f14a407e98f4509 (patch)
tree8724d2e8921c8ba28bd6682f17537eb84f6514b5 /modules/caddyhttp/vars.go
parent4fced0b6e15429dd51e6edc2c244f7af068ecf84 (diff)
caddyhttp: Clear out matcher error immediately after grabbing it (#4916)
Co-authored-by: Matthew Holt <mholt@users.noreply.github.com>
Diffstat (limited to 'modules/caddyhttp/vars.go')
-rw-r--r--modules/caddyhttp/vars.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/modules/caddyhttp/vars.go b/modules/caddyhttp/vars.go
index 28d0ddf..e7a7dbb 100644
--- a/modules/caddyhttp/vars.go
+++ b/modules/caddyhttp/vars.go
@@ -301,11 +301,21 @@ func GetVar(ctx context.Context, key string) interface{} {
// SetVar sets a value in the context's variable table with
// the given key. It overwrites any previous value with the
// same key.
+//
+// If the value is nil (note: non-nil interface with nil
+// underlying value does not count) and the key exists in
+// the table, the key+value will be deleted from the table.
func SetVar(ctx context.Context, key string, value interface{}) {
varMap, ok := ctx.Value(VarsCtxKey).(map[string]interface{})
if !ok {
return
}
+ if value == nil {
+ if _, ok := varMap[key]; ok {
+ delete(varMap, key)
+ return
+ }
+ }
varMap[key] = value
}