@marcel91200 / caddy Mirror · read-only / commits / ff2ba6de
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 13, 15:30 UTC

caddyhttp: Clear out matcher error immediately after grabbing it (#4916)

Co-authored-by: Matthew Holt <mholt@users.noreply.github.com>

Francis Lavoie committed Jul 28, 2022 at 17:19 UTC ff2ba6de8a312813140b5db24f14a407e98f4509
2 files changed +14
modules/caddyhttp/routes.go
+4
@@ -204,6 +204,10 @@ func wrapRoute(route Route) Middleware {
204 // the request and trigger the error handling chain
205 err, ok := GetVar(req.Context(), MatcherErrorVarKey).(error)
206 if ok {
207 + // clear out the error from context, otherwise
208 + // it will cascade to the error routes (#4916)
209 + SetVar(req.Context(), MatcherErrorVarKey, nil)
210 + // return the matcher's error
211 return err
212 }
213
modules/caddyhttp/vars.go
+10
@@ -301,11 +301,21 @@ func GetVar(ctx context.Context, key string) interface{} {
301 // SetVar sets a value in the context's variable table with
302 // the given key. It overwrites any previous value with the
303 // same key.
304 +//
305 +// If the value is nil (note: non-nil interface with nil
306 +// underlying value does not count) and the key exists in
307 +// the table, the key+value will be deleted from the table.
308 func SetVar(ctx context.Context, key string, value interface{}) {
309 varMap, ok := ctx.Value(VarsCtxKey).(map[string]interface{})
310 if !ok {
311 return
312 }
313 + if value == nil {
314 + if _, ok := varMap[key]; ok {
315 + delete(varMap, key)
316 + return
317 + }
318 + }
319 varMap[key] = value
320 }
321