diff options
author | Francis Lavoie <[email protected]> | 2022-04-25 12:47:12 -0400 |
---|---|---|
committer | GitHub <[email protected]> | 2022-04-25 10:47:12 -0600 |
commit | a8bb4a665af358f61a7ac0eabac8df2110cb6a36 (patch) | |
tree | fda9f8d00ae46996626cd9e007914ee56bed327d /caddyconfig/httpcaddyfile/directives.go | |
parent | 3a1e0dbf47429f3ae7ddcbbd9acc3707b0ad0083 (diff) | |
download | caddy-a8bb4a665af358f61a7ac0eabac8df2110cb6a36.tar.gz caddy-a8bb4a665af358f61a7ac0eabac8df2110cb6a36.zip |
httpcaddyfile: Add `{vars.*}` placeholder shortcut, reverse `vars` sort order (#4726)v2.5.0
* httpcaddyfile: Add `{vars.*}` placeholder shortcut
I'm yoinking this from my https://github.com/caddyserver/caddy/pull/4657 PR because I think we should get this in ASAP for v2.5.0 along with the new `vars` directive.
* Sort vars by matchers in reverse
Diffstat (limited to 'caddyconfig/httpcaddyfile/directives.go')
-rw-r--r-- | caddyconfig/httpcaddyfile/directives.go | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/caddyconfig/httpcaddyfile/directives.go b/caddyconfig/httpcaddyfile/directives.go index 6b80e346d..aaa8cb014 100644 --- a/caddyconfig/httpcaddyfile/directives.go +++ b/caddyconfig/httpcaddyfile/directives.go @@ -424,14 +424,29 @@ func sortRoutes(routes []ConfigValue) { jPathLen = len(jPM[0]) } - // if both directives have no path matcher, use whichever one - // has any kind of matcher defined first. - if iPathLen == 0 && jPathLen == 0 { - return len(iRoute.MatcherSetsRaw) > 0 && len(jRoute.MatcherSetsRaw) == 0 - } + // some directives involve setting values which can overwrite + // eachother, so it makes most sense to reverse the order so + // that the lease specific matcher is first; everything else + // has most-specific matcher first + if iDir == "vars" { + // if both directives have no path matcher, use whichever one + // has no matcher first. + if iPathLen == 0 && jPathLen == 0 { + return len(iRoute.MatcherSetsRaw) == 0 && len(jRoute.MatcherSetsRaw) > 0 + } + + // sort with the least-specific (shortest) path first + return iPathLen < jPathLen + } else { + // if both directives have no path matcher, use whichever one + // has any kind of matcher defined first. + if iPathLen == 0 && jPathLen == 0 { + return len(iRoute.MatcherSetsRaw) > 0 && len(jRoute.MatcherSetsRaw) == 0 + } - // sort with the most-specific (longest) path first - return iPathLen > jPathLen + // sort with the most-specific (longest) path first + return iPathLen > jPathLen + } }) } |