|
@ -379,7 +379,9 @@ func (s *Server) hasTLSClientAuth() bool { |
|
|
// that it is after any other host matcher but before any "catch-all"
|
|
|
// that it is after any other host matcher but before any "catch-all"
|
|
|
// route without a host matcher.
|
|
|
// route without a host matcher.
|
|
|
func (s *Server) findLastRouteWithHostMatcher() int { |
|
|
func (s *Server) findLastRouteWithHostMatcher() int { |
|
|
|
|
|
foundHostMatcher := false |
|
|
lastIndex := len(s.Routes) |
|
|
lastIndex := len(s.Routes) |
|
|
|
|
|
|
|
|
for i, route := range s.Routes { |
|
|
for i, route := range s.Routes { |
|
|
// since we want to break out of an inner loop, use a closure
|
|
|
// since we want to break out of an inner loop, use a closure
|
|
|
// to allow us to use 'return' when we found a host matcher
|
|
|
// to allow us to use 'return' when we found a host matcher
|
|
@ -388,6 +390,7 @@ func (s *Server) findLastRouteWithHostMatcher() int { |
|
|
for _, matcher := range sets { |
|
|
for _, matcher := range sets { |
|
|
switch matcher.(type) { |
|
|
switch matcher.(type) { |
|
|
case *MatchHost: |
|
|
case *MatchHost: |
|
|
|
|
|
foundHostMatcher = true |
|
|
return true |
|
|
return true |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -401,6 +404,14 @@ func (s *Server) findLastRouteWithHostMatcher() int { |
|
|
lastIndex = i + 1 |
|
|
lastIndex = i + 1 |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// If we didn't actually find a host matcher, return 0
|
|
|
|
|
|
// because that means every defined route was a "catch-all".
|
|
|
|
|
|
// See https://caddy.community/t/how-to-set-priority-in-caddyfile/13002/8
|
|
|
|
|
|
if !foundHostMatcher { |
|
|
|
|
|
return 0 |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return lastIndex |
|
|
return lastIndex |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|