Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -997,51 +998,51 @@ 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++;
}

if (sslConfig != null) {
if (socketCount > 0) {
serverListeningMessage.append(" and ");
}
serverListeningMessage
.append(String.format("https://%s:%s", getDeveloperFriendlyHostName(sslConfig), actualHttpsPort));
appendListeningMessage(serverListeningMessage, "https", httpServerOptions.getHost(), actualHttpsPort);
socketCount++;
}

if (domainSocketOptions != null) {
if (socketCount > 0) {
serverListeningMessage.append(" and ");
}
serverListeningMessage.append(String.format("unix:%s", getDeveloperFriendlyHostName(domainSocketOptions)));
serverListeningMessage.append(String.format("unix:%s", domainSocketOptions.getHost()));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Domain sockets don't understand the any address concept, so we don't need special handling here.

}
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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}

}
Loading