From fae064262d9c40393d634660b94d36ce6703aa1c Mon Sep 17 00:00:00 2001 From: Francis Lavoie Date: Tue, 19 May 2020 18:59:51 -0400 Subject: httpcaddyfile: Add `auto_https` global option (#3284) --- caddyconfig/httpcaddyfile/httptype.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'caddyconfig/httpcaddyfile/httptype.go') diff --git a/caddyconfig/httpcaddyfile/httptype.go b/caddyconfig/httpcaddyfile/httptype.go index 8e1ca74..fddb095 100644 --- a/caddyconfig/httpcaddyfile/httptype.go +++ b/caddyconfig/httpcaddyfile/httptype.go @@ -343,12 +343,27 @@ func (st *ServerType) serversFromPairings( if hsp, ok := options["https_port"].(int); ok { httpsPort = strconv.Itoa(hsp) } + autoHTTPS := "on" + if ah, ok := options["auto_https"].(string); ok { + autoHTTPS = ah + } for i, p := range pairings { srv := &caddyhttp.Server{ Listen: p.addresses, } + // handle the auto_https global option + if autoHTTPS != "on" { + srv.AutoHTTPS = new(caddyhttp.AutoHTTPSConfig) + if autoHTTPS == "off" { + srv.AutoHTTPS.Disabled = true + } + if autoHTTPS == "disable_redirects" { + srv.AutoHTTPS.DisableRedir = true + } + } + // sort server blocks by their keys; this is important because // only the first matching site should be evaluated, and we should // attempt to match most specific site first (host and path), in @@ -382,7 +397,7 @@ func (st *ServerType) serversFromPairings( }) var hasCatchAllTLSConnPolicy, addressQualifiesForTLS bool - autoHTTPSWillAddConnPolicy := true + autoHTTPSWillAddConnPolicy := autoHTTPS != "off" // create a subroute for each site in the server block for _, sblock := range p.serverBlocks { -- cgit v1.2.3