From 3a1e0dbf47429f3ae7ddcbbd9acc3707b0ad0083 Mon Sep 17 00:00:00 2001 From: Francis Lavoie Date: Mon, 25 Apr 2022 12:12:10 -0400 Subject: httpcaddyfile: Deprecate paths in site addresses; use zap logs (#4728) --- caddyconfig/caddyfile/parse.go | 4 ++-- caddyconfig/httpcaddyfile/httptype.go | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'caddyconfig') diff --git a/caddyconfig/caddyfile/parse.go b/caddyconfig/caddyfile/parse.go index b463238..2c2da0f 100644 --- a/caddyconfig/caddyfile/parse.go +++ b/caddyconfig/caddyfile/parse.go @@ -18,13 +18,13 @@ import ( "bytes" "fmt" "io" - "log" "os" "path/filepath" "strconv" "strings" "github.com/caddyserver/caddy/v2" + "go.uber.org/zap" ) // Parse parses the input just enough to group tokens, in @@ -393,7 +393,7 @@ func (p *parser) doImport() error { } if len(matches) == 0 { if strings.ContainsAny(globPattern, "*?[]") { - log.Printf("[WARNING] No files matching import glob pattern: %s", importPattern) + caddy.Log().Warn("No files matching import glob pattern", zap.String("pattern", importPattern)) } else { return p.Errf("File to import not found: %s", importPattern) } diff --git a/caddyconfig/httpcaddyfile/httptype.go b/caddyconfig/httpcaddyfile/httptype.go index f5dd68a..4f9f8d0 100644 --- a/caddyconfig/httpcaddyfile/httptype.go +++ b/caddyconfig/httpcaddyfile/httptype.go @@ -17,7 +17,6 @@ package httpcaddyfile import ( "encoding/json" "fmt" - "log" "reflect" "regexp" "sort" @@ -30,6 +29,7 @@ import ( "github.com/caddyserver/caddy/v2/modules/caddyhttp" "github.com/caddyserver/caddy/v2/modules/caddypki" "github.com/caddyserver/caddy/v2/modules/caddytls" + "go.uber.org/zap" ) func init() { @@ -458,6 +458,17 @@ func (st *ServerType) serversFromPairings( } } + // Using paths in site addresses is deprecated + // See ParseAddress() where parsing should later reject paths + // See https://github.com/caddyserver/caddy/pull/4728 for a full explanation + for _, sblock := range p.serverBlocks { + for _, addr := range sblock.keys { + if addr.Path != "" { + caddy.Log().Named("caddyfile").Warn("Using a path in a site address is deprecated; please use the 'handle' directive instead", zap.String("address", addr.String())) + } + } + } + // 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 @@ -545,7 +556,7 @@ func (st *ServerType) serversFromPairings( // emit warnings if user put unspecified IP addresses; they probably want the bind directive for _, h := range hosts { if h == "0.0.0.0" || h == "::" { - log.Printf("[WARNING] Site block has unspecified IP address %s which only matches requests having that Host header; you probably want the 'bind' directive to configure the socket", h) + caddy.Log().Named("caddyfile").Warn("Site block has an unspecified IP address which only matches requests having that Host header; you probably want the 'bind' directive to configure the socket", zap.String("address", h)) } } -- cgit v1.2.3