diff options
author | Francis Lavoie <[email protected]> | 2022-05-08 21:32:10 -0400 |
---|---|---|
committer | GitHub <[email protected]> | 2022-05-08 21:32:10 -0400 |
commit | b687d7b9670890efd8dc065fb7a025cd0c3a1445 (patch) | |
tree | 960d78a77556744576732a330a73b8364b7154fb /caddyconfig/httpcaddyfile/addresses.go | |
parent | f7be0ee10131f25620a2f64af7e3ded43eae2049 (diff) | |
download | caddy-b687d7b9670890efd8dc065fb7a025cd0c3a1445.tar.gz caddy-b687d7b9670890efd8dc065fb7a025cd0c3a1445.zip |
httpcaddyfile: Support multiple values for `default_bind` (#4774)
* httpcaddyfile: Support multiple values for `default_bind`
* Fix ordering of server blocks
Diffstat (limited to 'caddyconfig/httpcaddyfile/addresses.go')
-rw-r--r-- | caddyconfig/httpcaddyfile/addresses.go | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/caddyconfig/httpcaddyfile/addresses.go b/caddyconfig/httpcaddyfile/addresses.go index b33c0f053..c7923e81d 100644 --- a/caddyconfig/httpcaddyfile/addresses.go +++ b/caddyconfig/httpcaddyfile/addresses.go @@ -102,12 +102,20 @@ func (st *ServerType) mapAddressToServerBlocks(originalServerBlocks []serverBloc } } + // make a slice of the map keys so we can iterate in sorted order + addrs := make([]string, 0, len(addrToKeys)) + for k := range addrToKeys { + addrs = append(addrs, k) + } + sort.Strings(addrs) + // now that we know which addresses serve which keys of this // server block, we iterate that mapping and create a list of // new server blocks for each address where the keys of the // server block are only the ones which use the address; but // the contents (tokens) are of course the same - for addr, keys := range addrToKeys { + for _, addr := range addrs { + keys := addrToKeys[addr] // parse keys so that we only have to do it once parsedKeys := make([]Address, 0, len(keys)) for _, key := range keys { @@ -161,6 +169,7 @@ func (st *ServerType) consolidateAddrMappings(addrToServerBlocks map[string][]se delete(addrToServerBlocks, otherAddr) } } + sort.Strings(a.addresses) sbaddrs = append(sbaddrs, a) } @@ -208,13 +217,13 @@ func (st *ServerType) listenerAddrsForServerBlockKey(sblock serverBlock, key str } // the bind directive specifies hosts, but is optional - lnHosts := make([]string, 0, len(sblock.pile)) + lnHosts := make([]string, 0, len(sblock.pile["bind"])) for _, cfgVal := range sblock.pile["bind"] { lnHosts = append(lnHosts, cfgVal.Value.([]string)...) } if len(lnHosts) == 0 { - if defaultBind, ok := options["default_bind"].(string); ok { - lnHosts = []string{defaultBind} + if defaultBind, ok := options["default_bind"].([]string); ok { + lnHosts = defaultBind } else { lnHosts = []string{""} } @@ -236,6 +245,7 @@ func (st *ServerType) listenerAddrsForServerBlockKey(sblock serverBlock, key str for lnStr := range listeners { listenersList = append(listenersList, lnStr) } + sort.Strings(listenersList) return listenersList, nil } |