From 907e2d8d3a8ebaf14aa99939c493e56645bc2089 Mon Sep 17 00:00:00 2001 From: Francis Lavoie Date: Fri, 17 Sep 2021 02:52:32 -0400 Subject: caddyhttp: Add support for triggering errors from `try_files` (#4346) * caddyhttp: Add support for triggering errors from `try_files` * caddyhttp: Use vars instead of placeholders/replacer for matcher errors * caddyhttp: Add comment for matcher error var key --- modules/caddyhttp/routes.go | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'modules/caddyhttp/routes.go') diff --git a/modules/caddyhttp/routes.go b/modules/caddyhttp/routes.go index ebd763c..7b2871f 100644 --- a/modules/caddyhttp/routes.go +++ b/modules/caddyhttp/routes.go @@ -200,6 +200,15 @@ func wrapRoute(route Route) Middleware { // route must match at least one of the matcher sets if !route.MatcherSets.AnyMatch(req) { + // allow matchers the opportunity to short circuit + // the request and trigger the error handling chain + err, ok := GetVar(req.Context(), MatcherErrorVarKey).(error) + if ok { + return err + } + + // call the next handler, and skip this one, + // since the matcher didn't match return nextCopy.ServeHTTP(rw, req) } -- cgit v1.2.3