diff options
author | Matthew Holt <mholt@users.noreply.github.com> | 2020-04-02 14:20:30 -0600 |
---|---|---|
committer | Matthew Holt <mholt@users.noreply.github.com> | 2020-04-02 14:24:53 -0600 |
commit | 1c190b001b95e57d21dc63c01ae3c6de2a3fec57 (patch) | |
tree | 762fca56efffb3cedc7de7128f42c6c479e3a34f /caddyconfig/httpcaddyfile/addresses.go | |
parent | 3634c4593f2d9999dca2d7a02e23edc29bf7bd11 (diff) |
httpcaddyfile: Refactor site key parsing; detect conflicting schemes
We now store the parsed site/server block keys with the server block,
rather than parsing the addresses every time we read them.
Also detect conflicting schemes, i.e. TLS and non-TLS cannot be served
from the same server (natively -- modules could be built for it).
Also do not add site subroutes (subroutes generated specifically from
site blocks in the Caddyfile) that are empty.
Diffstat (limited to 'caddyconfig/httpcaddyfile/addresses.go')
-rw-r--r-- | caddyconfig/httpcaddyfile/addresses.go | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/caddyconfig/httpcaddyfile/addresses.go b/caddyconfig/httpcaddyfile/addresses.go index f5fd6b6..6545585 100644 --- a/caddyconfig/httpcaddyfile/addresses.go +++ b/caddyconfig/httpcaddyfile/addresses.go @@ -106,12 +106,22 @@ func (st *ServerType) mapAddressToServerBlocks(originalServerBlocks []serverBloc // server block are only the ones which use the address; but // the contents (tokens) are of course the same for addr, keys := range addrToKeys { + // parse keys so that we only have to do it once + parsedKeys := make([]Address, 0, len(keys)) + for _, key := range keys { + addr, err := ParseAddress(key) + if err != nil { + return nil, fmt.Errorf("parsing key '%s': %v", key, err) + } + parsedKeys = append(parsedKeys, addr.Normalize()) + } sbmap[addr] = append(sbmap[addr], serverBlock{ block: caddyfile.ServerBlock{ Keys: keys, Segments: sblock.block.Segments, }, pile: sblock.pile, + keys: parsedKeys, }) } } @@ -165,7 +175,7 @@ func (st *ServerType) listenerAddrsForServerBlockKey(sblock serverBlock, key str // figure out the HTTP and HTTPS ports; either // use defaults, or override with user config - httpPort, httpsPort := strconv.Itoa(certmagic.HTTPPort), strconv.Itoa(certmagic.HTTPSPort) + httpPort, httpsPort := strconv.Itoa(caddyhttp.DefaultHTTPPort), strconv.Itoa(caddyhttp.DefaultHTTPSPort) if hport, ok := options["http_port"]; ok { httpPort = strconv.Itoa(hport.(int)) } |