@marcel91200 / caddy Mirror · read-only / commits / 00e99df2
Fork 0

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

httpcaddyfile: Treat no matchers as 0-len path matchers (fix #3100)

+ a couple other minor changes from linter

Matthew Holt committed Feb 28, 2020 at 13:38 UTC 00e99df20952ac3e10377277d7fe13c85de4cb81
3 files changed +26 -26
caddyconfig/httpcaddyfile/builtins.go
+1 -1
@@ -37,7 +37,7 @@ func init() {
37 RegisterHandlerDirective("redir", parseRedir)
38 RegisterHandlerDirective("respond", parseRespond)
39 RegisterHandlerDirective("route", parseRoute)
40 - RegisterHandlerDirective("handle", parseSegmentAsSubroute)
40 + RegisterHandlerDirective("handle", parseHandle)
41 RegisterDirective("handle_errors", parseHandleErrors)
42 RegisterDirective("log", parseLog)
43 }
caddyconfig/httpcaddyfile/directives.go
+25 -20
@@ -283,27 +283,32 @@ func sortRoutes(routes []ConfigValue) {
283 return false
284 }
285
286 - if len(iRoute.MatcherSetsRaw) == 1 && len(jRoute.MatcherSetsRaw) == 1 {
287 - // use already-decoded matcher, or decode if it's the first time seeing it
288 - iPM, jPM := decodedMatchers[i], decodedMatchers[j]
289 - if iPM == nil {
290 - var pathMatcher caddyhttp.MatchPath
291 - _ = json.Unmarshal(iRoute.MatcherSetsRaw[0]["path"], &pathMatcher)
292 - decodedMatchers[i] = pathMatcher
293 - iPM = pathMatcher
294 - }
295 - if jPM == nil {
296 - var pathMatcher caddyhttp.MatchPath
297 - _ = json.Unmarshal(jRoute.MatcherSetsRaw[0]["path"], &pathMatcher)
298 - decodedMatchers[j] = pathMatcher
299 - jPM = pathMatcher
300 - }
286 + // use already-decoded matcher, or decode if it's the first time seeing it
287 + iPM, jPM := decodedMatchers[i], decodedMatchers[j]
288 + if iPM == nil && len(iRoute.MatcherSetsRaw) == 1 {
289 + var pathMatcher caddyhttp.MatchPath
290 + _ = json.Unmarshal(iRoute.MatcherSetsRaw[0]["path"], &pathMatcher)
291 + decodedMatchers[i] = pathMatcher
292 + iPM = pathMatcher
293 + }
294 + if jPM == nil && len(jRoute.MatcherSetsRaw) == 1 {
295 + var pathMatcher caddyhttp.MatchPath
296 + _ = json.Unmarshal(jRoute.MatcherSetsRaw[0]["path"], &pathMatcher)
297 + decodedMatchers[j] = pathMatcher
298 + jPM = pathMatcher
299 + }
300
302 - // if there is only one path in the matcher, sort by
303 - // longer path (more specific) first
304 - if len(iPM) == 1 && len(jPM) == 1 {
305 - return len(iPM[0]) > len(jPM[0])
306 - }
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])
312 }
313 }
314
caddyconfig/httpcaddyfile/httptype.go
-5
@@ -1012,11 +1012,6 @@ func (c counter) nextGroup() string {
1012 return name
1013 }
1014
1015 -type matcherSetAndTokens struct {
1016 - matcherSet caddy.ModuleMap
1017 - tokens []caddyfile.Token
1018 -}
1019 -
1015 type namedCustomLog struct {
1016 name string
1017 log *caddy.CustomLog