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

This commit is contained in:
Francis Lavoie 2022-04-28 10:18:45 -04:00 committed by GitHub
parent 3ab648382d
commit dcc98da4d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 3 deletions

View File

@ -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