Order of matchers execution inside named matcher

1. The problem I’m having:

I’m trying to understand the execution order of matchers inside named matcher. I have the following matcher:

@under_toggle {
  path /my_path
  featuretoggle "my_path_enabled" # custom plugin which implements .Match
}

handle @under_toggle {
  reverse_proxy { ... }
}

It works as expected and only handles requests if “my_path_enabled” feature is enabled (internally it matches request based on cookie value).

As feature toggle calculation can be expensive comparing to path matcher, I would like path matcher to be evaluated first and featuretoggle matcher to be evaluated only if path is correct. It is expensive because it uses growthbook.io rules evaluation engine under the hood

I see in logs that featuretoggle is executed every time for every path.
If I rename “featuretoggle” to “xtoggle” it starts to work as I expect: xtoggle is executed only if path matches.

I make an assumption that matchers are executed in alphabetical order, but I could not find it documented anywhere.

Could you confirm the order of matchers execution inside named matcher? (if there is any pre-defined order)

2. Error messages and/or full log output:

{"level":"debug","ts":"2025-01-02T16:39:26.892Z","logger":"http.matchers.featuretoggle","msg":"handling request","path":"/other/path"}

3. Caddy version:

2.8.4

4. How I installed and ran Caddy:

a. System environment:

Docker (https://hub.docker.com/_/caddy)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.