Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 14, 05:15 UTC
Simplify the logic in the previous commit
Matthew Holt committed
Feb 28, 2020 at 13:49 UTC
a60da8e7ab76a890566ce8047b92a7576a027e18
1 file changed
+9
-11
caddyconfig/httpcaddyfile/directives.go
+9
-11
@@ -298,18 +298,16 @@ func sortRoutes(routes []ConfigValue) {
298
jPM = pathMatcher
299
}
300
301
- // if there is only one path in the matcher, sort by
302
- // longer path (more specific) first; if one of the
303
- // routes doesn't have a matcher, then it's treated
304
- // like a zero-length path matcher
305
- switch {
306
- case iPM == nil && jPM != nil:
307
- return false
308
- case iPM != nil && jPM == nil:
309
- return true
310
- case iPM != nil && jPM != nil:
311
- return len(iPM[0]) > len(jPM[0])
301
+ // sort by longer path (more specific) first; missing
302
+ // path matchers are treated as zero-length paths
303
+ var iPathLen, jPathLen int
304
+ if iPM != nil {
305
+ iPathLen = len(iPM[0])
306
+ }
307
+ if jPM != nil {
308
+ jPathLen = len(jPM[0])
309
}
310
+ return iPathLen > jPathLen
311
}
312
313
return dirPositions[iDir] < dirPositions[jDir]