diff options
author | Francis Lavoie <[email protected]> | 2020-08-17 18:15:51 -0400 |
---|---|---|
committer | GitHub <[email protected]> | 2020-08-17 16:15:51 -0600 |
commit | 0afbab866794448fc0fe8b6cd6a299d7a078c2f1 (patch) | |
tree | 5f91223d2579f3a96c10087ab148ca2f16b7accb /caddyconfig/httpcaddyfile/directives.go | |
parent | fc65320e9c5b4e2ab96b6b421b65629560f1b8a2 (diff) | |
download | caddy-0afbab866794448fc0fe8b6cd6a299d7a078c2f1.tar.gz caddy-0afbab866794448fc0fe8b6cd6a299d7a078c2f1.zip |
httpcaddyfile: Improve directive sorting logic (#3658)
* httpcaddyfile: Flip `root` directive sort order
* httpcaddyfile: Sort directives with any matcher before those with none
* httpcaddyfile: Generalize reverse sort directives, improve logic
* httpcaddyfile: Fix "spelling" issue
* httpcaddyfile: Turns out the second change precludes the first
httpcaddyfile: Delete test that no longer makes sense
* httpcaddyfile: Shorten logic
Co-authored-by: Matt Holt <[email protected]>
Co-authored-by: Matt Holt <[email protected]>
Diffstat (limited to 'caddyconfig/httpcaddyfile/directives.go')
-rw-r--r-- | caddyconfig/httpcaddyfile/directives.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/caddyconfig/httpcaddyfile/directives.go b/caddyconfig/httpcaddyfile/directives.go index e93fdd034..d6af97dab 100644 --- a/caddyconfig/httpcaddyfile/directives.go +++ b/caddyconfig/httpcaddyfile/directives.go @@ -398,6 +398,14 @@ func sortRoutes(routes []ConfigValue) { if len(jPM) > 0 { 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 + } + + // sort with the most-specific (longest) path first return iPathLen > jPathLen }) } |