From 3d6fc1e1b7f41ebbd0c7cb48280ce1a14a56f4d5 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Fri, 3 Apr 2020 20:19:46 -0600 Subject: httpcaddyfile: Yield cleaner JSON when conn policy or log name is empty --- caddyconfig/httpcaddyfile/httptype.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'caddyconfig/httpcaddyfile') diff --git a/caddyconfig/httpcaddyfile/httptype.go b/caddyconfig/httpcaddyfile/httptype.go index 7fbf724..4e69895 100644 --- a/caddyconfig/httpcaddyfile/httptype.go +++ b/caddyconfig/httpcaddyfile/httptype.go @@ -449,7 +449,9 @@ func (st *ServerType) serversFromPairings( } } for _, h := range sblock.hostsFromKeys(true, true) { - srv.Logs.LoggerNames[h] = ncl.name + if ncl.name != "" { + srv.Logs.LoggerNames[h] = ncl.name + } } } } @@ -548,10 +550,22 @@ func detectConflictingSchemes(srv *caddyhttp.Server, serverBlocks []serverBlock, return nil } -// consolidateConnPolicies combines TLS connection policies that are the same, -// for a cleaner overall output. +// consolidateConnPolicies removes empty TLS connection policies and combines +// equivalent ones for a cleaner overall output. func consolidateConnPolicies(cps caddytls.ConnectionPolicies) (caddytls.ConnectionPolicies, error) { + empty := new(caddytls.ConnectionPolicy) + for i := 0; i < len(cps); i++ { + // if the connection policy is empty or has + // only matchers, we can remove it entirely + empty.MatchersRaw = cps[i].MatchersRaw + if reflect.DeepEqual(empty, cps[i]) { + cps = append(cps[:i], cps[i+1:]...) + i-- + continue + } + + // compare it to the others for j := 0; j < len(cps); j++ { if j == i { continue -- cgit v1.2.3