@marcel91200 / caddy Mirror · read-only / commits / d5341625
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

caddyhttp: Match hostnames with wildcards to loggers (#3378)

* adding wildcard matching of logger names * reordering precedence for more specific loggers to match first * removing dependence on certmagic and extra loop Co-authored-by: GregoryDosh <GregoryDosh@users.noreply.github.com>

Gregory Dosh committed May 11, 2020 at 15:17 UTC d5341625561bf67c40241a4fb649b0a4991e71b2
1 file changed +14
modules/caddyhttp/server.go
+14
@@ -456,6 +456,20 @@ func (slc ServerLogConfig) getLoggerName(host string) string {
456 if loggerName, ok := slc.LoggerNames[host]; ok {
457 return loggerName
458 }
459 +
460 + // Try matching wildcard domains if other non-specific loggers exist
461 + labels := strings.Split(host, ".")
462 + for i := range labels {
463 + if labels[i] == "" {
464 + continue
465 + }
466 + labels[i] = "*"
467 + wildcardHost := strings.Join(labels, ".")
468 + if loggerName, ok := slc.LoggerNames[wildcardHost]; ok {
469 + return loggerName
470 + }
471 + }
472 +
473 return slc.DefaultLoggerName
474 }
475