From dcc98da4d25dc13183f4bb4e913439a160bb1adf Mon Sep 17 00:00:00 2001 From: Francis Lavoie Date: Thu, 28 Apr 2022 10:18:45 -0400 Subject: caddyhttp: Improve listen addr error message for IPv6 (#4740) --- modules/caddyhttp/autohttps.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'modules/caddyhttp/autohttps.go') diff --git a/modules/caddyhttp/autohttps.go b/modules/caddyhttp/autohttps.go index f1d99ce..91611f9 100644 --- a/modules/caddyhttp/autohttps.go +++ b/modules/caddyhttp/autohttps.go @@ -222,11 +222,15 @@ func (app *App) automaticHTTPSPhase1(ctx caddy.Context, repl *caddy.Replacer) er app.logger.Info("enabling automatic HTTP->HTTPS redirects", zap.String("server_name", srvName)) // create HTTP->HTTPS redirects - for _, addr := range srv.Listen { + for _, listenAddr := range srv.Listen { // figure out the address we will redirect to... - addr, err := caddy.ParseNetworkAddress(addr) + addr, err := caddy.ParseNetworkAddress(listenAddr) if err != nil { - return fmt.Errorf("%s: invalid listener address: %v", srvName, addr) + msg := "%s: invalid listener address: %v" + if strings.Count(listenAddr, ":") > 1 { + msg = msg + ", there are too many colons, so the port is ambiguous. Did you mean to wrap the IPv6 address with [] brackets?" + } + return fmt.Errorf(msg, srvName, listenAddr) } // this address might not have a hostname, i.e. might be a -- cgit v1.2.3