httpcaddyfile: Fix ordering of catch-all site blocks

Catch-alls should always go last. Normally this is the case, but we have
a special case for comparing one wildcard-host site block to another
non-wildcard host site block; and a catch-all site block is also a
non-wildcard host site block, so now we have to special-case the
catch-all site block. Sigh.

This could be reproduced with a Caddyfile that has two site blocks:
":80" and "*.example.com", in that order.
This commit is contained in:
Matthew Holt 2020-06-16 10:02:06 -06:00
parent 003403ecbc
commit 32cafbb630
No known key found for this signature in database
GPG Key ID: 2A349DD577D586A5
1 changed files with 5 additions and 0 deletions

View File

@ -400,6 +400,11 @@ func (st *ServerType) serversFromPairings(
jLongestPath = addr.Path jLongestPath = addr.Path
} }
} }
if specificity(jLongestHost) == 0 {
// catch-all blocks (blocks with no hostname) should always go
// last, even after blocks with wildcard hosts
return true
}
if iWildcardHost != jWildcardHost { if iWildcardHost != jWildcardHost {
// site blocks that have a key with a wildcard in the hostname // site blocks that have a key with a wildcard in the hostname
// must always be less specific than blocks without one; see // must always be less specific than blocks without one; see