Skip to content

Commit

Permalink
httpcaddyfile: Yield cleaner JSON when conn policy or log name is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
mholt committed Apr 4, 2020
1 parent c7ac7de commit 3d6fc1e
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions caddyconfig/httpcaddyfile/httptype.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3d6fc1e

Please sign in to comment.