Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 13, 14:15 UTC
caddyhttp: Copy logger config to HTTP server during AutoHTTPS (#4990)
Francis Lavoie committed
Sep 1, 2022 at 23:31 UTC
d062fb40201b321c492da9b50ab8d107e0bb3c5f
2 files changed
+22
modules/caddyhttp/autohttps.go
+9
@@ -93,6 +93,9 @@ func (app *App) automaticHTTPSPhase1(ctx caddy.Context, repl *caddy.Replacer) er
93
// https://github.com/caddyserver/caddy/issues/3443)
94
redirDomains := make(map[string][]caddy.NetworkAddress)
95
96
+ // the configured logger for an HTTPS enabled server
97
+ var logger *ServerLogConfig
98
+
99
for srvName, srv := range app.Servers {
100
// as a prerequisite, provision route matchers; this is
101
// required for all routes on all servers, and must be
@@ -172,6 +175,11 @@ func (app *App) automaticHTTPSPhase1(ctx caddy.Context, repl *caddy.Replacer) er
175
continue
176
}
177
178
+ // clone the logger so we can apply it to the HTTP server
179
+ if srv.Logs != nil {
180
+ logger = srv.Logs.clone()
181
+ }
182
+
183
// for all the hostnames we found, filter them so we have
184
// a deduplicated list of names for which to obtain certs
185
// (only if cert management not disabled for this server)
@@ -400,6 +408,7 @@ redirServersLoop:
408
app.Servers["remaining_auto_https_redirects"] = &Server{
409
Listen: redirServerAddrsList,
410
Routes: appendCatchAll(redirRoutes),
411
+ Logs: logger,
412
}
413
}
414
modules/caddyhttp/server.go
+13
@@ -663,6 +663,19 @@ func (slc ServerLogConfig) getLoggerName(host string) string {
663
return slc.DefaultLoggerName
664
}
665
666
+func (slc *ServerLogConfig) clone() *ServerLogConfig {
667
+ clone := &ServerLogConfig{}
668
+ clone.DefaultLoggerName = slc.DefaultLoggerName
669
+ clone.LoggerNames = make(map[string]string)
670
+ for k, v := range slc.LoggerNames {
671
+ clone.LoggerNames[k] = v
672
+ }
673
+ clone.SkipHosts = append(clone.SkipHosts, slc.SkipHosts...)
674
+ clone.SkipUnmappedHosts = slc.SkipUnmappedHosts
675
+ clone.ShouldLogCredentials = slc.ShouldLogCredentials
676
+ return clone
677
+}
678
+
679
// PrepareRequest fills the request r for use in a Caddy HTTP handler chain. w and s can
680
// be nil, but the handlers will lose response placeholders and access to the server.
681
func PrepareRequest(r *http.Request, repl *caddy.Replacer, w http.ResponseWriter, s *Server) *http.Request {