summaryrefslogtreecommitdiff
path: root/caddyconfig/httpcaddyfile/directives.go
diff options
context:
space:
mode:
Diffstat (limited to 'caddyconfig/httpcaddyfile/directives.go')
-rw-r--r--caddyconfig/httpcaddyfile/directives.go29
1 files changed, 22 insertions, 7 deletions
diff --git a/caddyconfig/httpcaddyfile/directives.go b/caddyconfig/httpcaddyfile/directives.go
index 6b80e34..aaa8cb0 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
+ }
})
}