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

caddyhttp: Improve listen addr error message for IPv6 (#4740)

Francis Lavoie committed Apr 28, 2022 at 10:18 UTC dcc98da4d25dc13183f4bb4e913439a160bb1adf
1 file changed +7 -3
modules/caddyhttp/autohttps.go
+7 -3
@@ -222,11 +222,15 @@ func (app *App) automaticHTTPSPhase1(ctx caddy.Context, repl *caddy.Replacer) er
222 app.logger.Info("enabling automatic HTTP->HTTPS redirects", zap.String("server_name", srvName))
223
224 // create HTTP->HTTPS redirects
225 - for _, addr := range srv.Listen {
225 + for _, listenAddr := range srv.Listen {
226 // figure out the address we will redirect to...
227 - addr, err := caddy.ParseNetworkAddress(addr)
227 + addr, err := caddy.ParseNetworkAddress(listenAddr)
228 if err != nil {
229 - return fmt.Errorf("%s: invalid listener address: %v", srvName, addr)
229 + msg := "%s: invalid listener address: %v"
230 + if strings.Count(listenAddr, ":") > 1 {
231 + msg = msg + ", there are too many colons, so the port is ambiguous. Did you mean to wrap the IPv6 address with [] brackets?"
232 + }
233 + return fmt.Errorf(msg, srvName, listenAddr)
234 }
235
236 // this address might not have a hostname, i.e. might be a