@marcel91200 / caddy Mirror · read-only / commits / 3a1e0dbf
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 13, 19:15 UTC

httpcaddyfile: Deprecate paths in site addresses; use zap logs (#4728)

Francis Lavoie committed Apr 25, 2022 at 12:12 UTC 3a1e0dbf47429f3ae7ddcbbd9acc3707b0ad0083
5 files changed +23 -11
caddyconfig/caddyfile/parse.go
+2 -2
@@ -18,13 +18,13 @@ import (
18 "bytes"
19 "fmt"
20 "io"
21 - "log"
21 "os"
22 "path/filepath"
23 "strconv"
24 "strings"
25
26 "github.com/caddyserver/caddy/v2"
27 + "go.uber.org/zap"
28 )
29
30 // Parse parses the input just enough to group tokens, in
@@ -393,7 +393,7 @@ func (p *parser) doImport() error {
393 }
394 if len(matches) == 0 {
395 if strings.ContainsAny(globPattern, "*?[]") {
396 - log.Printf("[WARNING] No files matching import glob pattern: %s", importPattern)
396 + caddy.Log().Warn("No files matching import glob pattern", zap.String("pattern", importPattern))
397 } else {
398 return p.Errf("File to import not found: %s", importPattern)
399 }
caddyconfig/httpcaddyfile/httptype.go
+13 -2
@@ -17,7 +17,6 @@ package httpcaddyfile
17 import (
18 "encoding/json"
19 "fmt"
20 - "log"
20 "reflect"
21 "regexp"
22 "sort"
@@ -30,6 +29,7 @@ import (
29 "github.com/caddyserver/caddy/v2/modules/caddyhttp"
30 "github.com/caddyserver/caddy/v2/modules/caddypki"
31 "github.com/caddyserver/caddy/v2/modules/caddytls"
32 + "go.uber.org/zap"
33 )
34
35 func init() {
@@ -458,6 +458,17 @@ func (st *ServerType) serversFromPairings(
458 }
459 }
460
461 + // Using paths in site addresses is deprecated
462 + // See ParseAddress() where parsing should later reject paths
463 + // See https://github.com/caddyserver/caddy/pull/4728 for a full explanation
464 + for _, sblock := range p.serverBlocks {
465 + for _, addr := range sblock.keys {
466 + if addr.Path != "" {
467 + 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()))
468 + }
469 + }
470 + }
471 +
472 // sort server blocks by their keys; this is important because
473 // only the first matching site should be evaluated, and we should
474 // attempt to match most specific site first (host and path), in
@@ -545,7 +556,7 @@ func (st *ServerType) serversFromPairings(
556 // emit warnings if user put unspecified IP addresses; they probably want the bind directive
557 for _, h := range hosts {
558 if h == "0.0.0.0" || h == "::" {
548 - 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)
559 + 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))
560 }
561 }
562
cmd/commandfuncs.go
+3 -1
@@ -496,7 +496,9 @@ func cmdAdaptConfig(fl Flags) (int, error) {
496 if warn.Directive != "" {
497 msg = fmt.Sprintf("%s: %s", warn.Directive, warn.Message)
498 }
499 - fmt.Fprintf(os.Stderr, "[WARNING][%s] %s:%d: %s\n", adaptCmdAdapterFlag, warn.File, warn.Line, msg)
499 + caddy.Log().Named(adaptCmdAdapterFlag).Warn(msg,
500 + zap.String("file", warn.File),
501 + zap.Int("line", warn.Line))
502 }
503
504 // validate output if requested
modules/caddyhttp/fileserver/command.go
+1 -1
@@ -129,7 +129,7 @@ func cmdFileServer(fs caddycmd.Flags) (int, error) {
129 return caddy.ExitCodeFailedStartup, err
130 }
131
132 - log.Printf("Caddy 2 serving static files on %s", listen)
132 + log.Printf("Caddy serving static files on %s", listen)
133
134 select {}
135 }
modules/caddyhttp/reverseproxy/caddyfile.go
+4 -5
@@ -15,7 +15,6 @@
15 package reverseproxy
16
17 import (
18 - "log"
18 "net"
19 "net/http"
20 "reflect"
@@ -552,16 +551,16 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
551 case 2:
552 // some lint checks, I guess
553 if strings.EqualFold(args[0], "host") && (args[1] == "{hostport}" || args[1] == "{http.request.hostport}") {
555 - log.Printf("[WARNING] Unnecessary header_up ('Host' field): the reverse proxy's default behavior is to pass headers to the upstream")
554 + caddy.Log().Named("caddyfile").Warn("Unnecessary header_up Host: the reverse proxy's default behavior is to pass headers to the upstream")
555 }
556 if strings.EqualFold(args[0], "x-forwarded-for") && (args[1] == "{remote}" || args[1] == "{http.request.remote}" || args[1] == "{remote_host}" || args[1] == "{http.request.remote.host}") {
558 - log.Printf("[WARNING] Unnecessary header_up ('X-Forwarded-For' field): the reverse proxy's default behavior is to pass headers to the upstream")
557 + caddy.Log().Named("caddyfile").Warn("Unnecessary header_up X-Forwarded-For: the reverse proxy's default behavior is to pass headers to the upstream")
558 }
559 if strings.EqualFold(args[0], "x-forwarded-proto") && (args[1] == "{scheme}" || args[1] == "{http.request.scheme}") {
561 - log.Printf("[WARNING] Unnecessary header_up ('X-Forwarded-Proto' field): the reverse proxy's default behavior is to pass headers to the upstream")
560 + caddy.Log().Named("caddyfile").Warn("Unnecessary header_up X-Forwarded-Proto: the reverse proxy's default behavior is to pass headers to the upstream")
561 }
562 if strings.EqualFold(args[0], "x-forwarded-host") && (args[1] == "{host}" || args[1] == "{http.request.host}" || args[1] == "{hostport}" || args[1] == "{http.request.hostport}") {
564 - log.Printf("[WARNING] Unnecessary header_up ('X-Forwarded-Host' field): the reverse proxy's default behavior is to pass headers to the upstream")
563 + caddy.Log().Named("caddyfile").Warn("Unnecessary header_up X-Forwarded-Host: the reverse proxy's default behavior is to pass headers to the upstream")
564 }
565 err = headers.CaddyfileHeaderOp(h.Headers.Request, args[0], args[1], "")
566 case 3: