From 1c190b001b95e57d21dc63c01ae3c6de2a3fec57 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Thu, 2 Apr 2020 14:20:30 -0600 Subject: 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. --- caddyconfig/httpcaddyfile/tlsapp.go | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) (limited to 'caddyconfig/httpcaddyfile/tlsapp.go') diff --git a/caddyconfig/httpcaddyfile/tlsapp.go b/caddyconfig/httpcaddyfile/tlsapp.go index db3d13b..6214d61 100644 --- a/caddyconfig/httpcaddyfile/tlsapp.go +++ b/caddyconfig/httpcaddyfile/tlsapp.go @@ -43,26 +43,16 @@ func (st ServerType) buildTLSApp( hostsSharedWithHostlessKey := make(map[string]struct{}) for _, pair := range pairings { for _, sb := range pair.serverBlocks { - for _, key := range sb.block.Keys { - addr, err := ParseAddress(key) - if err != nil { - return nil, warnings, err - } - addr = addr.Normalize() + for _, addr := range sb.keys { if addr.Host == "" { serverBlocksWithHostlessKey++ // this server block has a hostless key, now // go through and add all the hosts to the set - for _, otherKey := range sb.block.Keys { - if otherKey == key { + for _, otherAddr := range sb.keys { + if otherAddr.Original == addr.Original { continue } - addr, err := ParseAddress(otherKey) - if err != nil { - return nil, warnings, err - } - addr = addr.Normalize() - if addr.Host != "" { + if otherAddr.Host != "" { hostsSharedWithHostlessKey[addr.Host] = struct{}{} } } @@ -82,10 +72,7 @@ func (st ServerType) buildTLSApp( // get values that populate an automation policy for this block var ap *caddytls.AutomationPolicy - sblockHosts, err := st.hostsFromServerBlockKeys(sblock.block, false, false) - if err != nil { - return nil, warnings, err - } + sblockHosts := sblock.hostsFromKeys(false, false) if len(sblockHosts) == 0 { ap = catchAllAP } -- cgit v1.2.3