8373807: test/jdk/java/net/httpclient/websocket/DummyWebSocketServer.java getURI() uses "localhost"

Reviewed-by: jpai
This commit is contained in:
Daniel Fuchs 2025-12-17 18:44:49 +00:00
parent 4e05748f08
commit f3a48560b5

View File

@ -351,7 +351,14 @@ public class DummyWebSocketServer implements Closeable {
if (!started.get()) {
throw new IllegalStateException("Not yet started");
}
return URI.create("ws://localhost:" + address.getPort());
String ip = address.getAddress().isAnyLocalAddress()
? InetAddress.getLoopbackAddress().getHostAddress()
: address.getAddress().getHostAddress();
if (ip.indexOf(':') >= 0) {
ip = String.format("[%s]", ip);
}
return URI.create("ws://" + ip + ":" + address.getPort());
}
private boolean readRequest(SocketChannel channel, StringBuilder request)