@marcel91200 / caddy Mirror · read-only / commits / 2f59467a
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 14, 05:15 UTC

httpcaddyfile: Only append TLS conn policy if it's non-empty (#3319)

This can lead to nicer, smaller JSON output for Caddyfiles like this: a { tls internal } b { tls foo@bar.com } i.e. where the tls directive only configures automation policies, and is merely meant to enable TLS on a server block (if it wasn't implied). This helps keeps implicit config implicit. Needs a little more testing to ensure it doesn't break anything important.

Matt Holt committed May 5, 2020 at 12:37 UTC 2f59467ac3b8f31b0f2ad9af346bb52a045a3db2
2 files changed +17 -1
caddyconfig/httpcaddyfile/httptype.go
+4 -1
@@ -416,7 +416,10 @@ func (st *ServerType) serversFromPairings(
416 hasCatchAllTLSConnPolicy = true
417 }
418
419 - srv.TLSConnPolicies = append(srv.TLSConnPolicies, cp)
419 + // only append this policy if it actually changes something
420 + if !cp.SettingsEmpty() {
421 + srv.TLSConnPolicies = append(srv.TLSConnPolicies, cp)
422 + }
423 }
424 }
425
modules/caddytls/connpolicy.go
+13
@@ -264,6 +264,19 @@ func (p *ConnectionPolicy) buildStandardTLSConfig(ctx caddy.Context) error {
264 return nil
265 }
266
267 +// SettingsEmpty returns true if p's settings (fields
268 +// except the matchers) are all empty/unset.
269 +func (p ConnectionPolicy) SettingsEmpty() bool {
270 + return p.CertSelection == nil &&
271 + p.CipherSuites == nil &&
272 + p.Curves == nil &&
273 + p.ALPN == nil &&
274 + p.ProtocolMin == "" &&
275 + p.ProtocolMax == "" &&
276 + p.ClientAuthentication == nil &&
277 + p.DefaultSNI == ""
278 +}
279 +
280 // ClientAuthentication configures TLS client auth.
281 type ClientAuthentication struct {
282 // A list of base64 DER-encoded CA certificates