Skip to content

Commit

Permalink
httpcaddyfile: Fix ordering of catch-all site blocks
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mholt committed Jun 16, 2020
1 parent 003403e commit 32cafbb
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions caddyconfig/httpcaddyfile/httptype.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,11 @@ func (st *ServerType) serversFromPairings(
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 {
// site blocks that have a key with a wildcard in the hostname
// must always be less specific than blocks without one; see
Expand Down

0 comments on commit 32cafbb

Please sign in to comment.