diff --git a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java index d97ae42cc7a5f..0118bb5cf516f 100644 --- a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java +++ b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java @@ -47,6 +47,7 @@ import io.netty.channel.ChannelInitializer; import io.netty.handler.codec.http.HttpHeaderNames; import io.netty.handler.codec.http.HttpResponseStatus; +import io.netty.util.NetUtil; import io.quarkus.arc.Arc; import io.quarkus.arc.ArcContainer; import io.quarkus.arc.InstanceHandle; @@ -997,8 +998,7 @@ private static void setHttpServerTiming(boolean httpDisabled, HttpServerOptions int socketCount = 0; if (!httpDisabled && httpServerOptions != null) { - serverListeningMessage.append(String.format( - "http://%s:%s", getDeveloperFriendlyHostName(httpServerOptions), actualHttpPort)); + appendListeningMessage(serverListeningMessage, "http", httpServerOptions.getHost(), actualHttpPort); socketCount++; } @@ -1006,8 +1006,7 @@ private static void setHttpServerTiming(boolean httpDisabled, HttpServerOptions if (socketCount > 0) { serverListeningMessage.append(" and "); } - serverListeningMessage - .append(String.format("https://%s:%s", getDeveloperFriendlyHostName(sslConfig), actualHttpsPort)); + appendListeningMessage(serverListeningMessage, "https", httpServerOptions.getHost(), actualHttpsPort); socketCount++; } @@ -1015,33 +1014,35 @@ private static void setHttpServerTiming(boolean httpDisabled, HttpServerOptions if (socketCount > 0) { serverListeningMessage.append(" and "); } - serverListeningMessage.append(String.format("unix:%s", getDeveloperFriendlyHostName(domainSocketOptions))); + serverListeningMessage.append(String.format("unix:%s", domainSocketOptions.getHost())); } if (managementConfig != null) { - serverListeningMessage.append( - String.format(". Management interface listening on http%s://%s:%s.", managementConfig.isSsl() ? "s" : "", - getDeveloperFriendlyHostName(managementConfig), actualManagementPort)); + serverListeningMessage.append(". Management interface listening on "); + appendListeningMessage(serverListeningMessage, managementConfig.isSsl() ? "https" : "http", + managementConfig.getHost(), actualManagementPort); } Timing.setHttpServer(serverListeningMessage.toString(), auxiliaryApplication); } - /** - * To improve developer experience in WSL dev/test mode, the server listening message should print "localhost" when - * the host is set to "0.0.0.0". Otherwise, display the actual host. - * Do not use this during the actual configuration, use options.getHost() there directly instead. - */ - private static String getDeveloperFriendlyHostName(HttpServerOptions options) { - return (LaunchMode.current().isDevOrTest() && "0.0.0.0".equals(options.getHost()) && isWSL()) ? "localhost" - : options.getHost(); + static void appendListeningMessage(StringBuilder builder, String protocol, String host, int port) { + boolean ipv6 = NetUtil.isValidIpV6Address(host); + if ((ipv6 && isAnyBindAddress(NetUtil.createByteArrayFromIpAddressString(host))) || "0.0.0.0".equals(host)) { + builder.append("all addresses including "); + host = "localhost"; // don't show the any bind address in a url + ipv6 = false; + } + builder.append(String.format("%s://%s:%s", protocol, + (ipv6 && !host.startsWith("[")) ? ("[" + host + "]") : host, port)); } - /** - * @return {@code true} if the application is running in a WSL (Windows Subsystem for Linux) environment - */ - private static boolean isWSL() { - var sysEnv = System.getenv(); - return sysEnv.containsKey("IS_WSL") || sysEnv.containsKey("WSL_DISTRO_NAME"); + private static boolean isAnyBindAddress(byte[] bytes) { + for (byte b : bytes) { + if (b != 0x00) { + return false; + } + } + return true; } private static HttpServerOptions createHttpServerOptions( diff --git a/extensions/vertx-http/runtime/src/test/java/io/quarkus/vertx/http/runtime/VertxHttpRecorderTest.java b/extensions/vertx-http/runtime/src/test/java/io/quarkus/vertx/http/runtime/VertxHttpRecorderTest.java new file mode 100644 index 0000000000000..5a50d44a1b31c --- /dev/null +++ b/extensions/vertx-http/runtime/src/test/java/io/quarkus/vertx/http/runtime/VertxHttpRecorderTest.java @@ -0,0 +1,32 @@ +package io.quarkus.vertx.http.runtime; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.io.IOException; + +import org.junit.jupiter.api.Test; + +class VertxHttpRecorderTest { + + @Test + void testListeningOnIpv6Any() throws IOException { + StringBuilder builder = new StringBuilder(); + VertxHttpRecorder.appendListeningMessage(builder, "https", "::", 123); + assertEquals("all addresses including https://localhost:123", builder.toString()); + } + + @Test + void testListeningOnIpv4Any() throws IOException { + StringBuilder builder = new StringBuilder(); + VertxHttpRecorder.appendListeningMessage(builder, "http", "0.0.0.0", 123); + assertEquals("all addresses including http://localhost:123", builder.toString()); + } + + @Test + void testListeningOnHost() throws IOException { + StringBuilder builder = new StringBuilder(); + VertxHttpRecorder.appendListeningMessage(builder, "http", "localhost4", 8080); + assertEquals("http://localhost4:8080", builder.toString()); + } + +}