# HG changeset patch # User chegar # Date 1520530936 0 # Node ID ec34ae013fbe99b7580752c8d9deb41875ddc8b2 # Parent c012b93297b036b0ec033759ce2849d32d29c850 http-client-branch: tests should bind to the loopback only diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/AbstractNoBody.java --- a/test/jdk/java/net/httpclient/AbstractNoBody.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/AbstractNoBody.java Thu Mar 08 17:42:16 2018 +0000 @@ -23,6 +23,7 @@ import java.io.IOException; import java.io.InputStream; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; @@ -91,6 +92,11 @@ .build(); } + static String serverAuthority(HttpServer server) { + return InetAddress.getLoopbackAddress().getHostName() + ":" + + server.getAddress().getPort(); + } + @BeforeTest public void setup() throws Exception { printStamp(START, "setup"); @@ -101,39 +107,37 @@ // HTTP/1.1 HttpHandler h1_fixedLengthNoBodyHandler = new HTTP1_FixedLengthNoBodyHandler(); HttpHandler h1_chunkNoBodyHandler = new HTTP1_ChunkedNoBodyHandler(); - InetSocketAddress sa = new InetSocketAddress(0); + InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0); httpTestServer = HttpServer.create(sa, 0); httpTestServer.setExecutor(serverExecutor); httpTestServer.createContext("/http1/noBodyFixed", h1_fixedLengthNoBodyHandler); httpTestServer.createContext("/http1/noBodyChunk", h1_chunkNoBodyHandler); - httpURI_fixed = "http://127.0.0.1:" + httpTestServer.getAddress().getPort() + "/http1/noBodyFixed"; - httpURI_chunk = "http://127.0.0.1:" + httpTestServer.getAddress().getPort() + "/http1/noBodyChunk"; + httpURI_fixed = "http://" + serverAuthority(httpTestServer) + "/http1/noBodyFixed"; + httpURI_chunk = "http://" + serverAuthority(httpTestServer) + "/http1/noBodyChunk"; httpsTestServer = HttpsServer.create(sa, 0); httpsTestServer.setExecutor(serverExecutor); httpsTestServer.setHttpsConfigurator(new HttpsConfigurator(sslContext)); httpsTestServer.createContext("/https1/noBodyFixed", h1_fixedLengthNoBodyHandler); httpsTestServer.createContext("/https1/noBodyChunk", h1_chunkNoBodyHandler); - httpsURI_fixed = "https://127.0.0.1:" + httpsTestServer.getAddress().getPort() + "/https1/noBodyFixed"; - httpsURI_chunk = "https://127.0.0.1:" + httpsTestServer.getAddress().getPort() + "/https1/noBodyChunk"; + httpsURI_fixed = "https://" + serverAuthority(httpsTestServer) + "/https1/noBodyFixed"; + httpsURI_chunk = "https://" + serverAuthority(httpsTestServer) + "/https1/noBodyChunk"; // HTTP/2 Http2Handler h2_fixedLengthNoBodyHandler = new HTTP2_FixedLengthNoBodyHandler(); Http2Handler h2_chunkedNoBodyHandler = new HTTP2_ChunkedNoBodyHandler(); - http2TestServer = new Http2TestServer("127.0.0.1", false, 0, serverExecutor, null); + http2TestServer = new Http2TestServer("localhost", false, 0, serverExecutor, null); http2TestServer.addHandler(h2_fixedLengthNoBodyHandler, "/http2/noBodyFixed"); http2TestServer.addHandler(h2_chunkedNoBodyHandler, "/http2/noBodyChunk"); - int port = http2TestServer.getAddress().getPort(); - http2URI_fixed = "http://127.0.0.1:" + port + "/http2/noBodyFixed"; - http2URI_chunk = "http://127.0.0.1:" + port + "/http2/noBodyChunk"; + http2URI_fixed = "http://" + http2TestServer.serverAuthority() + "/http2/noBodyFixed"; + http2URI_chunk = "http://" + http2TestServer.serverAuthority() + "/http2/noBodyChunk"; - https2TestServer = new Http2TestServer("127.0.0.1", true, 0, serverExecutor, sslContext); + https2TestServer = new Http2TestServer("localhost", true, 0, serverExecutor, sslContext); https2TestServer.addHandler(h2_fixedLengthNoBodyHandler, "/https2/noBodyFixed"); https2TestServer.addHandler(h2_chunkedNoBodyHandler, "/https2/noBodyChunk"); - port = https2TestServer.getAddress().getPort(); - https2URI_fixed = "https://127.0.0.1:" + port + "/https2/noBodyFixed"; - https2URI_chunk = "https://127.0.0.1:" + port + "/https2/noBodyChunk"; + https2URI_fixed = "https://" + https2TestServer.serverAuthority() + "/https2/noBodyFixed"; + https2URI_chunk = "https://" + https2TestServer.serverAuthority() + "/https2/noBodyChunk"; httpTestServer.start(); httpsTestServer.start(); diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/AsFileDownloadTest.java --- a/test/jdk/java/net/httpclient/AsFileDownloadTest.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/AsFileDownloadTest.java Thu Mar 08 17:42:16 2018 +0000 @@ -49,6 +49,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.UncheckedIOException; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.URI; import java.net.http.HttpClient; @@ -252,6 +253,11 @@ // -- Infrastructure + static String serverAuthority(HttpServer server) { + return InetAddress.getLoopbackAddress().getHostName() + ":" + + server.getAddress().getPort(); + } + @BeforeTest public void setup() throws Exception { tempDir = Paths.get("asFileDownloadTest.tmp.dir"); @@ -276,25 +282,23 @@ if (sslContext == null) throw new AssertionError("Unexpected null sslContext"); - InetSocketAddress sa = new InetSocketAddress(0); + InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0); httpTestServer = HttpServer.create(sa, 0); httpTestServer.createContext("/http1/afdt", new Http1FileDispoHandler()); - httpURI = "http://127.0.0.1:" + httpTestServer.getAddress().getPort() + "/http1/afdt"; + httpURI = "http://" + serverAuthority(httpTestServer) + "/http1/afdt"; httpsTestServer = HttpsServer.create(sa, 0); httpsTestServer.setHttpsConfigurator(new HttpsConfigurator(sslContext)); httpsTestServer.createContext("/https1/afdt", new Http1FileDispoHandler()); - httpsURI = "https://127.0.0.1:" + httpsTestServer.getAddress().getPort() + "/https1/afdt"; + httpsURI = "https://" + serverAuthority(httpsTestServer) + "/https1/afdt"; - http2TestServer = new Http2TestServer("127.0.0.1", false, 0); + http2TestServer = new Http2TestServer("localhost", false, 0); http2TestServer.addHandler(new Http2FileDispoHandler(), "/http2/afdt"); - int port = http2TestServer.getAddress().getPort(); - http2URI = "http://127.0.0.1:" + port + "/http2/afdt"; + http2URI = "http://" + http2TestServer.serverAuthority() + "/http2/afdt"; - https2TestServer = new Http2TestServer("127.0.0.1", true, 0); + https2TestServer = new Http2TestServer("localhost", true, 0); https2TestServer.addHandler(new Http2FileDispoHandler(), "/https2/afdt"); - port = https2TestServer.getAddress().getPort(); - https2URI = "https://127.0.0.1:" + port + "/https2/afdt"; + https2URI = "https://" + https2TestServer.serverAuthority() + "/https2/afdt"; httpTestServer.start(); httpsTestServer.start(); diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/AsFileDownloadTest.policy --- a/test/jdk/java/net/httpclient/AsFileDownloadTest.policy Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/AsFileDownloadTest.policy Thu Mar 08 17:42:16 2018 +0000 @@ -34,7 +34,7 @@ permission java.lang.RuntimePermission "accessClassInPackage.jdk.internal.net.http.hpack"; permission java.lang.RuntimePermission "accessClassInPackage.sun.net.www.http"; - permission java.net.SocketPermission "127.0.0.1:*", "accept,resolve"; + permission java.net.SocketPermission "localhost:*", "accept,resolve"; permission java.lang.RuntimePermission "modifyThread"; }; @@ -42,10 +42,10 @@ permission java.io.FilePermission "${user.dir}${/}asFileDownloadTest.tmp.dir", "read,write"; permission java.io.FilePermission "${user.dir}${/}asFileDownloadTest.tmp.dir/-", "read,write"; - permission java.net.URLPermission "http://127.0.0.1:*/http1/afdt", "POST"; - permission java.net.URLPermission "https://127.0.0.1:*/https1/afdt", "POST"; - permission java.net.URLPermission "http://127.0.0.1:*/http2/afdt", "POST"; - permission java.net.URLPermission "https://127.0.0.1:*/https2/afdt", "POST"; + permission java.net.URLPermission "http://localhost:*/http1/afdt", "POST"; + permission java.net.URLPermission "https://localhost:*/https1/afdt", "POST"; + permission java.net.URLPermission "http://localhost:*/http2/afdt", "POST"; + permission java.net.URLPermission "https://localhost:*/https2/afdt", "POST"; // needed to grant permission to the HTTP/2 server @@ -58,7 +58,7 @@ permission java.util.logging.LoggingPermission "control"; // needed to grant the HTTP servers - permission java.net.SocketPermission "127.0.0.1:*", "accept,resolve"; + permission java.net.SocketPermission "localhost:*", "accept,resolve"; permission java.util.PropertyPermission "*", "read"; permission java.lang.RuntimePermission "modifyThread"; diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/BasicAuthTest.java --- a/test/jdk/java/net/httpclient/BasicAuthTest.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/BasicAuthTest.java Thu Mar 08 17:42:16 2018 +0000 @@ -38,6 +38,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.PasswordAuthentication; import java.net.URI; @@ -57,7 +58,8 @@ static final String POST_BODY = "This is the POST body 123909090909090"; public static void main(String[] args) throws Exception { - HttpServer server = HttpServer.create(new InetSocketAddress(0), 10); + InetSocketAddress addr = new InetSocketAddress(InetAddress.getLoopbackAddress(),0); + HttpServer server = HttpServer.create(addr, 10); ExecutorService e = Executors.newCachedThreadPool(); Handler h = new Handler(); HttpContext serverContext = server.createContext("/test", h); @@ -74,7 +76,7 @@ .build(); try { - URI uri = new URI("http://127.0.0.1:" + Integer.toString(port) + "/test/foo"); + URI uri = new URI("http://localhost:" + Integer.toString(port) + "/test/foo"); HttpRequest req = HttpRequest.newBuilder(uri).GET().build(); HttpResponse resp = client.send(req, BodyHandlers.ofString()); diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/BasicRedirectTest.java --- a/test/jdk/java/net/httpclient/BasicRedirectTest.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/BasicRedirectTest.java Thu Mar 08 17:42:16 2018 +0000 @@ -44,6 +44,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.URI; import java.net.http.HttpClient; @@ -223,38 +224,38 @@ if (sslContext == null) throw new AssertionError("Unexpected null sslContext"); - InetSocketAddress sa = new InetSocketAddress(0); + InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0); httpTestServer = HttpTestServer.of(HttpServer.create(sa, 0)); httpTestServer.addHandler(new BasicHttpRedirectHandler(), "/http1/same/"); - httpURI = "http://127.0.0.1:" + httpTestServer.getAddress().getPort() + "/http1/same/redirect"; + httpURI = "http://" + httpTestServer.serverAuthority() + "/http1/same/redirect"; HttpsServer httpsServer = HttpsServer.create(sa, 0); httpsServer.setHttpsConfigurator(new HttpsConfigurator(sslContext)); httpsTestServer = HttpTestServer.of(httpsServer); httpsTestServer.addHandler(new BasicHttpRedirectHandler(),"/https1/same/"); - httpsURI = "https://127.0.0.1:" + httpsTestServer.getAddress().getPort() + "/https1/same/redirect"; + httpsURI = "https://" + httpsTestServer.serverAuthority() + "/https1/same/redirect"; - http2TestServer = HttpTestServer.of(new Http2TestServer("127.0.0.1", false, 0)); + http2TestServer = HttpTestServer.of(new Http2TestServer("localhost", false, 0)); http2TestServer.addHandler(new BasicHttpRedirectHandler(), "/http2/same/"); - http2URI = "http://127.0.0.1:" + http2TestServer.getAddress().getPort() + "/http2/same/redirect"; - https2TestServer = HttpTestServer.of(new Http2TestServer("127.0.0.1", true, 0)); + http2URI = "http://" + http2TestServer.serverAuthority() + "/http2/same/redirect"; + https2TestServer = HttpTestServer.of(new Http2TestServer("localhost", true, 0)); https2TestServer.addHandler(new BasicHttpRedirectHandler(), "/https2/same/"); - https2URI = "https://127.0.0.1:" + https2TestServer.getAddress().getPort() + "/https2/same/redirect"; + https2URI = "https://" + https2TestServer.serverAuthority() + "/https2/same/redirect"; // HTTP to HTTPS redirect handler httpTestServer.addHandler(new ToSecureHttpRedirectHandler(httpsURI), "/http1/toSecure/"); - httpURIToMoreSecure = "http://127.0.0.1:" + httpTestServer.getAddress().getPort() + "/http1/toSecure/redirect"; + httpURIToMoreSecure = "http://" + httpTestServer.serverAuthority()+ "/http1/toSecure/redirect"; // HTTP2 to HTTP2S redirect handler http2TestServer.addHandler(new ToSecureHttpRedirectHandler(https2URI), "/http2/toSecure/"); - http2URIToMoreSecure = "http://127.0.0.1:" + http2TestServer.getAddress().getPort() + "/http2/toSecure/redirect"; + http2URIToMoreSecure = "http://" + http2TestServer.serverAuthority() + "/http2/toSecure/redirect"; // HTTPS to HTTP redirect handler httpsTestServer.addHandler(new ToLessSecureRedirectHandler(httpURI), "/https1/toLessSecure/"); - httpsURIToLessSecure = "https://127.0.0.1:" + httpsTestServer.getAddress().getPort() + "/https1/toLessSecure/redirect"; + httpsURIToLessSecure = "https://" + httpsTestServer.serverAuthority() + "/https1/toLessSecure/redirect"; // HTTPS2 to HTTP2 redirect handler https2TestServer.addHandler(new ToLessSecureRedirectHandler(http2URI), "/https2/toLessSecure/"); - https2URIToLessSecure = "https://127.0.0.1:" + https2TestServer.getAddress().getPort() + "/https2/toLessSecure/redirect"; + https2URIToLessSecure = "https://" + https2TestServer.serverAuthority() + "/https2/toLessSecure/redirect"; httpTestServer.start(); httpsTestServer.start(); diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/ConcurrentResponses.java --- a/test/jdk/java/net/httpclient/ConcurrentResponses.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/ConcurrentResponses.java Thu Mar 08 17:42:16 2018 +0000 @@ -41,6 +41,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.URI; import java.nio.ByteBuffer; @@ -248,6 +249,10 @@ } } + static String serverAuthority(HttpServer server) { + return InetAddress.getLoopbackAddress().getHostName() + ":" + + server.getAddress().getPort(); + } @BeforeTest public void setup() throws Exception { @@ -255,31 +260,31 @@ if (sslContext == null) throw new AssertionError("Unexpected null sslContext"); - InetSocketAddress sa = new InetSocketAddress(0); + InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0); httpTestServer = HttpServer.create(sa, 0); httpTestServer.createContext("/http1/fixed", new Http1FixedHandler()); - httpFixedURI = "http://127.0.0.1:" + httpTestServer.getAddress().getPort() + "/http1/fixed"; + httpFixedURI = "http://" + serverAuthority(httpTestServer) + "/http1/fixed"; httpTestServer.createContext("/http1/chunked", new Http1ChunkedHandler()); - httpChunkedURI = "http://127.0.0.1:" + httpTestServer.getAddress().getPort() + "/http1/chunked"; + httpChunkedURI = "http://" + serverAuthority(httpTestServer) + "/http1/chunked"; httpsTestServer = HttpsServer.create(sa, 0); httpsTestServer.setHttpsConfigurator(new HttpsConfigurator(sslContext)); httpsTestServer.createContext("/https1/fixed", new Http1FixedHandler()); - httpsFixedURI = "https://127.0.0.1:" + httpsTestServer.getAddress().getPort() + "/https1/fixed"; + httpsFixedURI = "https://" + serverAuthority(httpsTestServer) + "/https1/fixed"; httpsTestServer.createContext("/https1/chunked", new Http1ChunkedHandler()); - httpsChunkedURI = "https://127.0.0.1:" + httpsTestServer.getAddress().getPort() + "/https1/chunked"; + httpsChunkedURI = "https://" + serverAuthority(httpsTestServer) + "/https1/chunked"; - http2TestServer = new Http2TestServer("127.0.0.1", false, 0); + http2TestServer = new Http2TestServer("localhost", false, 0); http2TestServer.addHandler(new Http2FixedHandler(), "/http2/fixed"); - http2FixedURI = "http://127.0.0.1:" + http2TestServer.getAddress().getPort() + "/http2/fixed"; + http2FixedURI = "http://" + http2TestServer.serverAuthority()+ "/http2/fixed"; http2TestServer.addHandler(new Http2VariableHandler(), "/http2/variable"); - http2VariableURI = "http://127.0.0.1:" + http2TestServer.getAddress().getPort() + "/http2/variable"; + http2VariableURI = "http://" + http2TestServer.serverAuthority() + "/http2/variable"; - https2TestServer = new Http2TestServer("127.0.0.1", true, 0); + https2TestServer = new Http2TestServer("localhost", true, 0); https2TestServer.addHandler(new Http2FixedHandler(), "/https2/fixed"); - https2FixedURI = "https://127.0.0.1:" + https2TestServer.getAddress().getPort() + "/https2/fixed"; + https2FixedURI = "https://" + https2TestServer.serverAuthority() + "/https2/fixed"; https2TestServer.addHandler(new Http2VariableHandler(), "/https2/variable"); - https2VariableURI = "https://127.0.0.1:" + https2TestServer.getAddress().getPort() + "/https2/variable"; + https2VariableURI = "https://" + https2TestServer.serverAuthority() + "/https2/variable"; httpTestServer.start(); httpsTestServer.start(); diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/CustomRequestPublisher.java --- a/test/jdk/java/net/httpclient/CustomRequestPublisher.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/CustomRequestPublisher.java Thu Mar 08 17:42:16 2018 +0000 @@ -44,6 +44,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.URI; import java.nio.ByteBuffer; @@ -314,31 +315,34 @@ } } + static String serverAuthority(HttpServer server) { + return InetAddress.getLoopbackAddress().getHostName() + ":" + + server.getAddress().getPort(); + } + @BeforeTest public void setup() throws Exception { sslContext = new SimpleSSLContext().get(); if (sslContext == null) throw new AssertionError("Unexpected null sslContext"); - InetSocketAddress sa = new InetSocketAddress("localhost", 0); + InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0); httpTestServer = HttpServer.create(sa, 0); httpTestServer.createContext("/http1/echo", new Http1EchoHandler()); - httpURI = "http://127.0.0.1:" + httpTestServer.getAddress().getPort() + "/http1/echo"; + httpURI = "http://" + serverAuthority(httpTestServer) + "/http1/echo"; httpsTestServer = HttpsServer.create(sa, 0); httpsTestServer.setHttpsConfigurator(new HttpsConfigurator(sslContext)); httpsTestServer.createContext("/https1/echo", new Http1EchoHandler()); - httpsURI = "https://127.0.0.1:" + httpsTestServer.getAddress().getPort() + "/https1/echo"; + httpsURI = "https://" + serverAuthority(httpsTestServer) + "/https1/echo"; - http2TestServer = new Http2TestServer("127.0.0.1", false, 0); + http2TestServer = new Http2TestServer("localhost", false, 0); http2TestServer.addHandler(new Http2EchoHandler(), "/http2/echo"); - int port = http2TestServer.getAddress().getPort(); - http2URI = "http://127.0.0.1:" + port + "/http2/echo"; + http2URI = "http://" + http2TestServer.serverAuthority() + "/http2/echo"; - https2TestServer = new Http2TestServer("127.0.0.1", true, 0); + https2TestServer = new Http2TestServer("localhost", true, 0); https2TestServer.addHandler(new Http2EchoHandler(), "/https2/echo"); - port = https2TestServer.getAddress().getPort(); - https2URI = "https://127.0.0.1:" + port + "/https2/echo"; + https2URI = "https://" + https2TestServer.serverAuthority() + "/https2/echo"; httpTestServer.start(); httpsTestServer.start(); diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/CustomResponseSubscriber.java --- a/test/jdk/java/net/httpclient/CustomResponseSubscriber.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/CustomResponseSubscriber.java Thu Mar 08 17:42:16 2018 +0000 @@ -35,6 +35,7 @@ import java.io.IOException; import java.io.InputStream; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.URI; import java.nio.ByteBuffer; @@ -178,6 +179,10 @@ } } + static String serverAuthority(HttpServer server) { + return InetAddress.getLoopbackAddress().getHostName() + ":" + + server.getAddress().getPort(); + } @BeforeTest public void setup() throws Exception { @@ -188,37 +193,35 @@ // HTTP/1.1 HttpHandler h1_fixedLengthHandler = new HTTP1_FixedLengthHandler(); HttpHandler h1_chunkHandler = new HTTP1_ChunkedHandler(); - InetSocketAddress sa = new InetSocketAddress(0); + InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0); httpTestServer = HttpServer.create(sa, 0); httpTestServer.createContext("/http1/fixed", h1_fixedLengthHandler); httpTestServer.createContext("/http1/chunk", h1_chunkHandler); - httpURI_fixed = "http://127.0.0.1:" + httpTestServer.getAddress().getPort() + "/http1/fixed"; - httpURI_chunk = "http://127.0.0.1:" + httpTestServer.getAddress().getPort() + "/http1/chunk"; + httpURI_fixed = "http://" + serverAuthority(httpTestServer) + "/http1/fixed"; + httpURI_chunk = "http://" + serverAuthority(httpTestServer) + "/http1/chunk"; httpsTestServer = HttpsServer.create(sa, 0); httpsTestServer.setHttpsConfigurator(new HttpsConfigurator(sslContext)); httpsTestServer.createContext("/https1/fixed", h1_fixedLengthHandler); httpsTestServer.createContext("/https1/chunk", h1_chunkHandler); - httpsURI_fixed = "https://127.0.0.1:" + httpsTestServer.getAddress().getPort() + "/https1/fixed"; - httpsURI_chunk = "https://127.0.0.1:" + httpsTestServer.getAddress().getPort() + "/https1/chunk"; + httpsURI_fixed = "https://" + serverAuthority(httpsTestServer) + "/https1/fixed"; + httpsURI_chunk = "https://" + serverAuthority(httpsTestServer) + "/https1/chunk"; // HTTP/2 Http2Handler h2_fixedLengthHandler = new HTTP2_FixedLengthHandler(); Http2Handler h2_chunkedHandler = new HTTP2_VariableHandler(); - http2TestServer = new Http2TestServer("127.0.0.1", false, 0); + http2TestServer = new Http2TestServer("localhost", false, 0); http2TestServer.addHandler(h2_fixedLengthHandler, "/http2/fixed"); http2TestServer.addHandler(h2_chunkedHandler, "/http2/chunk"); - int port = http2TestServer.getAddress().getPort(); - http2URI_fixed = "http://127.0.0.1:" + port + "/http2/fixed"; - http2URI_chunk = "http://127.0.0.1:" + port + "/http2/chunk"; + http2URI_fixed = "http://" + http2TestServer.serverAuthority() + "/http2/fixed"; + http2URI_chunk = "http://" + http2TestServer.serverAuthority() + "/http2/chunk"; - https2TestServer = new Http2TestServer("127.0.0.1", true, 0); + https2TestServer = new Http2TestServer("localhost", true, 0); https2TestServer.addHandler(h2_fixedLengthHandler, "/https2/fixed"); https2TestServer.addHandler(h2_chunkedHandler, "/https2/chunk"); - port = https2TestServer.getAddress().getPort(); - https2URI_fixed = "https://127.0.0.1:" + port + "/https2/fixed"; - https2URI_chunk = "https://127.0.0.1:" + port + "/https2/chunk"; + https2URI_fixed = "https://" + https2TestServer.serverAuthority() + "/https2/fixed"; + https2URI_chunk = "https://" + https2TestServer.serverAuthority() + "/https2/chunk"; httpTestServer.start(); httpsTestServer.start(); diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/DigestEchoServer.java --- a/test/jdk/java/net/httpclient/DigestEchoServer.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/DigestEchoServer.java Thu Mar 08 17:42:16 2018 +0000 @@ -37,6 +37,7 @@ import java.math.BigInteger; import java.net.Authenticator; import java.net.HttpURLConnection; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.MalformedURLException; import java.net.PasswordAuthentication; @@ -250,7 +251,7 @@ for (int i = 1; i <= max; i++) { B bindable = createBindable(); InetSocketAddress address = getAddress(bindable); - String key = "127.0.0.1:" + address.getPort(); + String key = "localhost:" + address.getPort(); if (addresses.addIfAbsent(key)) { System.out.println("Socket bound to: " + key + " after " + i + " attempt(s)"); @@ -295,7 +296,7 @@ protected ServerSocket createBindable() throws IOException { ServerSocket ss = new ServerSocket(); ss.setReuseAddress(false); - ss.bind(new InetSocketAddress(0)); + ss.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0)); return ss; } @@ -318,7 +319,7 @@ @Override protected S createBindable() throws IOException { S server = newHttpServer(); - server.bind(new InetSocketAddress( 0), 0); + server.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), 0); return server; } @@ -381,7 +382,7 @@ @Override protected Http2TestServer newHttpServer() throws Exception { - return new Http2TestServer("127.0.0.1", false, 0); + return new Http2TestServer("localhost", false, 0); } } @@ -394,7 +395,7 @@ @Override protected Http2TestServer newHttpServer() throws Exception { - return new Http2TestServer("127.0.0.1", true, 0); + return new Http2TestServer("localhost", true, 0); } } @@ -602,17 +603,17 @@ } public InetSocketAddress getAddress() { - return new InetSocketAddress("127.0.0.1", + return new InetSocketAddress(InetAddress.getLoopbackAddress(), serverImpl.getAddress().getPort()); } public InetSocketAddress getServerAddress() { - return new InetSocketAddress("127.0.0.1", + return new InetSocketAddress(InetAddress.getLoopbackAddress(), serverImpl.getAddress().getPort()); } public InetSocketAddress getProxyAddress() { - return new InetSocketAddress("127.0.0.1", + return new InetSocketAddress(InetAddress.getLoopbackAddress(), serverImpl.getAddress().getPort()); } @@ -1557,7 +1558,7 @@ @Override public InetSocketAddress getAddress() { - return new InetSocketAddress("127.0.0.1", + return new InetSocketAddress(InetAddress.getLoopbackAddress(), ss.getLocalPort()); } @Override diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/EscapedOctetsInURI.java --- a/test/jdk/java/net/httpclient/EscapedOctetsInURI.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/EscapedOctetsInURI.java Thu Mar 08 17:42:16 2018 +0000 @@ -47,6 +47,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.URI; import javax.net.ssl.SSLContext; @@ -165,7 +166,10 @@ } } - + static String serverAuthority(HttpServer server) { + return InetAddress.getLoopbackAddress().getHostName() + ":" + + server.getAddress().getPort(); + } @BeforeTest public void setup() throws Exception { @@ -173,25 +177,23 @@ if (sslContext == null) throw new AssertionError("Unexpected null sslContext"); - InetSocketAddress sa = new InetSocketAddress("localhost", 0); + InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0); httpTestServer = HttpServer.create(sa, 0); httpTestServer.createContext("/http1", new Http1ASCIIUriStringHandler()); - httpURI = "http://127.0.0.1:" + httpTestServer.getAddress().getPort() + "/http1"; + httpURI = "http://" + serverAuthority(httpTestServer) + "/http1"; httpsTestServer = HttpsServer.create(sa, 0); httpsTestServer.setHttpsConfigurator(new HttpsConfigurator(sslContext)); httpsTestServer.createContext("/https1", new Http1ASCIIUriStringHandler()); - httpsURI = "https://127.0.0.1:" + httpsTestServer.getAddress().getPort() + "/https1"; + httpsURI = "https://" + serverAuthority(httpsTestServer) + "/https1"; - http2TestServer = new Http2TestServer("127.0.0.1", false, 0); + http2TestServer = new Http2TestServer("localhost", false, 0); http2TestServer.addHandler(new HttpASCIIUriStringHandler(), "/http2"); - int port = http2TestServer.getAddress().getPort(); - http2URI = "http://127.0.0.1:" + port + "/http2"; + http2URI = "http://" + http2TestServer.serverAuthority() + "/http2"; - https2TestServer = new Http2TestServer("127.0.0.1", true, 0); + https2TestServer = new Http2TestServer("localhost", true, 0); https2TestServer.addHandler(new HttpASCIIUriStringHandler(), "/https2"); - port = https2TestServer.getAddress().getPort(); - https2URI = "https://127.0.0.1:" + port + "/https2"; + https2URI = "https://" + https2TestServer.serverAuthority() + "/https2"; httpTestServer.start(); httpsTestServer.start(); diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/ExpectContinue.java --- a/test/jdk/java/net/httpclient/ExpectContinue.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/ExpectContinue.java Thu Mar 08 17:42:16 2018 +0000 @@ -39,6 +39,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.URI; import java.net.http.HttpClient; @@ -130,21 +131,26 @@ // -- Infrastructure + static String serverAuthority(HttpServer server) { + return InetAddress.getLoopbackAddress().getHostName() + ":" + + server.getAddress().getPort(); + } + @BeforeTest public void setup() throws Exception { sslContext = new SimpleSSLContext().get(); if (sslContext == null) throw new AssertionError("Unexpected null sslContext"); - InetSocketAddress sa = new InetSocketAddress(0); + InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0); httpTestServer = HttpServer.create(sa, 0); httpTestServer.createContext("/http1/ec", new Http1ExpectContinueHandler()); - httpURI = "http://127.0.0.1:" + httpTestServer.getAddress().getPort() + "/http1/ec"; + httpURI = "http://" + serverAuthority(httpTestServer) + "/http1/ec"; httpsTestServer = HttpsServer.create(sa, 0); httpsTestServer.setHttpsConfigurator(new HttpsConfigurator(sslContext)); httpsTestServer.createContext("/https1/ec", new Http1ExpectContinueHandler()); - httpsURI = "https://127.0.0.1:" + httpsTestServer.getAddress().getPort() + "/https1/ec"; + httpsURI = "https://" + serverAuthority(httpsTestServer) + "/https1/ec"; httpTestServer.start(); httpsTestServer.start(); diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/FlowAdapterPublisherTest.java --- a/test/jdk/java/net/httpclient/FlowAdapterPublisherTest.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/FlowAdapterPublisherTest.java Thu Mar 08 17:42:16 2018 +0000 @@ -24,6 +24,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.URI; import java.nio.ByteBuffer; @@ -333,31 +334,34 @@ } } + static String serverAuthority(HttpServer server) { + return InetAddress.getLoopbackAddress().getHostName() + ":" + + server.getAddress().getPort(); + } + @BeforeTest public void setup() throws Exception { sslContext = new SimpleSSLContext().get(); if (sslContext == null) throw new AssertionError("Unexpected null sslContext"); - InetSocketAddress sa = new InetSocketAddress(0); + InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(),0); httpTestServer = HttpServer.create(sa, 0); httpTestServer.createContext("/http1/echo", new Http1EchoHandler()); - httpURI = "http://127.0.0.1:" + httpTestServer.getAddress().getPort() + "/http1/echo"; + httpURI = "http://" + serverAuthority(httpTestServer) + "/http1/echo"; httpsTestServer = HttpsServer.create(sa, 0); httpsTestServer.setHttpsConfigurator(new HttpsConfigurator(sslContext)); httpsTestServer.createContext("/https1/echo", new Http1EchoHandler()); - httpsURI = "https://127.0.0.1:" + httpsTestServer.getAddress().getPort() + "/https1/echo"; + httpsURI = "https://" + serverAuthority(httpsTestServer) + "/https1/echo"; - http2TestServer = new Http2TestServer("127.0.0.1", false, 0); + http2TestServer = new Http2TestServer("localhost", false, 0); http2TestServer.addHandler(new Http2EchoHandler(), "/http2/echo"); - int port = http2TestServer.getAddress().getPort(); - http2URI = "http://127.0.0.1:" + port + "/http2/echo"; + http2URI = "http://" + http2TestServer.serverAuthority() + "/http2/echo"; - https2TestServer = new Http2TestServer("127.0.0.1", true, 0); + https2TestServer = new Http2TestServer("localhost", true, 0); https2TestServer.addHandler(new Http2EchoHandler(), "/https2/echo"); - port = https2TestServer.getAddress().getPort(); - https2URI = "https://127.0.0.1:" + port + "/https2/echo"; + https2URI = "https://" + https2TestServer.serverAuthority() + "/https2/echo"; httpTestServer.start(); httpsTestServer.start(); diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/FlowAdapterSubscriberTest.java --- a/test/jdk/java/net/httpclient/FlowAdapterSubscriberTest.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/FlowAdapterSubscriberTest.java Thu Mar 08 17:42:16 2018 +0000 @@ -26,6 +26,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.UncheckedIOException; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.URI; import java.nio.ByteBuffer; @@ -508,31 +509,34 @@ return response; } + static String serverAuthority(HttpServer server) { + return InetAddress.getLoopbackAddress().getHostName() + ":" + + server.getAddress().getPort(); + } + @BeforeTest public void setup() throws Exception { sslContext = new SimpleSSLContext().get(); if (sslContext == null) throw new AssertionError("Unexpected null sslContext"); - InetSocketAddress sa = new InetSocketAddress("localhost", 0); + InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0); httpTestServer = HttpServer.create(sa, 0); httpTestServer.createContext("/http1/echo", new Http1EchoHandler()); - httpURI = "http://127.0.0.1:" + httpTestServer.getAddress().getPort() + "/http1/echo"; + httpURI = "http://" + serverAuthority(httpTestServer) + "/http1/echo"; httpsTestServer = HttpsServer.create(sa, 0); httpsTestServer.setHttpsConfigurator(new HttpsConfigurator(sslContext)); httpsTestServer.createContext("/https1/echo", new Http1EchoHandler()); - httpsURI = "https://127.0.0.1:" + httpsTestServer.getAddress().getPort() + "/https1/echo"; + httpsURI = "https://" + serverAuthority(httpsTestServer) + "/https1/echo"; - http2TestServer = new Http2TestServer("127.0.0.1", false, 0); + http2TestServer = new Http2TestServer("localhost", false, 0); http2TestServer.addHandler(new Http2EchoHandler(), "/http2/echo"); - int port = http2TestServer.getAddress().getPort(); - http2URI = "http://127.0.0.1:" + port + "/http2/echo"; + http2URI = "http://" + http2TestServer.serverAuthority() + "/http2/echo"; - https2TestServer = new Http2TestServer("127.0.0.1", true, 0); + https2TestServer = new Http2TestServer("localhost", true, 0); https2TestServer.addHandler(new Http2EchoHandler(), "/https2/echo"); - port = https2TestServer.getAddress().getPort(); - https2URI = "https://127.0.0.1:" + port + "/https2/echo"; + https2URI = "https://" + https2TestServer.serverAuthority() + "/https2/echo"; httpTestServer.start(); httpsTestServer.start(); diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/HandshakeFailureTest.java --- a/test/jdk/java/net/httpclient/HandshakeFailureTest.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/HandshakeFailureTest.java Thu Mar 08 17:42:16 2018 +0000 @@ -28,6 +28,7 @@ import java.io.DataInputStream; import java.io.IOException; import java.io.UncheckedIOException; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.ServerSocket; import java.net.Socket; @@ -64,7 +65,7 @@ for (AbstractServer server : servers) { try (server) { out.format("%n%n------ Testing with server:%s ------%n", server); - URI uri = new URI("https://127.0.0.1:" + server.getPort() + "/"); + URI uri = new URI("https://localhost:" + server.getPort() + "/"); test.testSyncSameClient(uri, Version.HTTP_1_1); test.testSyncSameClient(uri, Version.HTTP_2); @@ -175,7 +176,7 @@ AbstractServer(String name, ServerSocket ss) throws IOException { super(name); ss.setReuseAddress(false); - ss.bind(new InetSocketAddress(0)); + ss.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0)); this.ss = ss; this.start(); } diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/HeadersTest1.java --- a/test/jdk/java/net/httpclient/HeadersTest1.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/HeadersTest1.java Thu Mar 08 17:42:16 2018 +0000 @@ -31,6 +31,7 @@ import java.io.IOException; import java.io.OutputStream; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.URI; import java.net.http.HttpClient; @@ -61,7 +62,8 @@ @Test public void test() throws Exception { - HttpServer server = HttpServer.create(new InetSocketAddress(0), 10); + InetSocketAddress addr = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0); + HttpServer server = HttpServer.create(addr, 10); Handler h = new Handler(); server.createContext("/test", h); int port = server.getAddress().getPort(); @@ -75,7 +77,7 @@ .build(); try { - URI uri = new URI("http://127.0.0.1:" + Integer.toString(port) + "/test/foo"); + URI uri = new URI("http://localhost:" + port + "/test/foo"); HttpRequest req = HttpRequest.newBuilder(uri) .headers("X-Bar", "foo1") .headers("X-Bar", "foo2") diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/HttpServerAdapters.java --- a/test/jdk/java/net/httpclient/HttpServerAdapters.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/HttpServerAdapters.java Thu Mar 08 17:42:16 2018 +0000 @@ -59,15 +59,15 @@ * * URI http1URI, http2URI; * - * InetSocketAddress sa = new InetSocketAddress("localhost", 0); + * InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0); * HttpTestServer server1 = HttpTestServer.of(HttpServer.create(sa, 0)); * HttpTestContext context = server.addHandler(new HttpTestEchoHandler(), "/http1/echo"); - * http2URI = "http://127.0.0.1:" + server1.getAddress().getPort() + "/http1/echo"; + * http2URI = "http://localhost:" + server1.getAddress().getPort() + "/http1/echo"; * - * Http2TestServer http2TestServer = new Http2TestServer("127.0.0.1", false, 0); + * Http2TestServer http2TestServer = new Http2TestServer("localhost", false, 0); * HttpTestServer server2 = HttpTestServer.of(http2TestServer); * server2.addHandler(new HttpTestEchoHandler(), "/http2/echo"); - * http1URI = "http://127.0.0.1:" + server2.getAddress().getPort() + "/http2/echo"; + * http1URI = "http://localhost:" + server2.getAddress().getPort() + "/http2/echo"; * * } */ @@ -483,7 +483,7 @@ } @Override public InetSocketAddress getAddress() { - return new InetSocketAddress("127.0.0.1", + return new InetSocketAddress(InetAddress.getLoopbackAddress(), impl.getAddress().getPort()); } public Version getVersion() { return Version.HTTP_1_1; } @@ -533,7 +533,7 @@ } @Override public InetSocketAddress getAddress() { - return new InetSocketAddress("127.0.0.1", + return new InetSocketAddress(InetAddress.getLoopbackAddress(), impl.getAddress().getPort()); } public Version getVersion() { return Version.HTTP_2; } diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/HttpsTunnelTest.java --- a/test/jdk/java/net/httpclient/HttpsTunnelTest.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/HttpsTunnelTest.java Thu Mar 08 17:42:16 2018 +0000 @@ -25,6 +25,7 @@ import com.sun.net.httpserver.HttpsServer; import jdk.testlibrary.SimpleSSLContext; import javax.net.ssl.SSLContext; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.ProxySelector; import java.net.URI; @@ -97,7 +98,7 @@ } public static void main(String[] args) throws Exception { - InetSocketAddress sa = new InetSocketAddress(0); + InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0); HttpsServer server1 = HttpsServer.create(sa, 0); server1.setHttpsConfigurator(new HttpsConfigurator(context)); HttpTestServer http1Server = @@ -105,7 +106,7 @@ http1Server.addHandler(new HttpTestEchoHandler(), "/"); http1Server.start(); HttpTestServer http2Server = HttpTestServer.of( - new Http2TestServer("127.0.0.1", true, 0)); + new Http2TestServer("localhost", true, 0)); http2Server.addHandler(new HttpTestEchoHandler(), "/"); http2Server.start(); @@ -113,8 +114,8 @@ DigestEchoServer.HttpAuthSchemeType.NONE); try { - URI uri1 = new URI("https:/" + http1Server.getAddress() + "/foo/https1"); - URI uri2 = new URI("https:/" + http2Server.getAddress() + "/foo/https2"); + URI uri1 = new URI("https://" + http1Server.serverAuthority() + "/foo/https1"); + URI uri2 = new URI("https://" + http2Server.serverAuthority() + "/foo/https2"); ProxySelector ps = ProxySelector.of(proxy.getProxyAddress()); //HttpClient.Builder.NO_PROXY; HttpsTunnelTest test = new HttpsTunnelTest(); diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/ImmutableFlowItems.java --- a/test/jdk/java/net/httpclient/ImmutableFlowItems.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/ImmutableFlowItems.java Thu Mar 08 17:42:16 2018 +0000 @@ -37,6 +37,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.URI; import java.nio.ByteBuffer; @@ -167,6 +168,10 @@ assertThrows(UOE, () -> list.remove(b)); } + static String serverAuthority(HttpServer server) { + return InetAddress.getLoopbackAddress().getHostName() + ":" + + server.getAddress().getPort(); + } @BeforeTest public void setup() throws Exception { @@ -177,37 +182,35 @@ // HTTP/1.1 HttpHandler h1_fixedLengthHandler = new HTTP1_FixedLengthHandler(); HttpHandler h1_chunkHandler = new HTTP1_ChunkedHandler(); - InetSocketAddress sa = new InetSocketAddress("localhost", 0); + InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0); httpTestServer = HttpServer.create(sa, 0); httpTestServer.createContext("/http1/fixed", h1_fixedLengthHandler); httpTestServer.createContext("/http1/chunk", h1_chunkHandler); - httpURI_fixed = "http://127.0.0.1:" + httpTestServer.getAddress().getPort() + "/http1/fixed"; - httpURI_chunk = "http://127.0.0.1:" + httpTestServer.getAddress().getPort() + "/http1/chunk"; + httpURI_fixed = "http://" + serverAuthority(httpTestServer) + "/http1/fixed"; + httpURI_chunk = "http://" + serverAuthority(httpTestServer) + "/http1/chunk"; httpsTestServer = HttpsServer.create(sa, 0); httpsTestServer.setHttpsConfigurator(new HttpsConfigurator(sslContext)); httpsTestServer.createContext("/https1/fixed", h1_fixedLengthHandler); httpsTestServer.createContext("/https1/chunk", h1_chunkHandler); - httpsURI_fixed = "https://127.0.0.1:" + httpsTestServer.getAddress().getPort() + "/https1/fixed"; - httpsURI_chunk = "https://127.0.0.1:" + httpsTestServer.getAddress().getPort() + "/https1/chunk"; + httpsURI_fixed = "https://" + serverAuthority(httpsTestServer) + "/https1/fixed"; + httpsURI_chunk = "https://" + serverAuthority(httpsTestServer) + "/https1/chunk"; // HTTP/2 Http2Handler h2_fixedLengthHandler = new HTTP2_FixedLengthHandler(); Http2Handler h2_chunkedHandler = new HTTP2_VariableHandler(); - http2TestServer = new Http2TestServer("127.0.0.1", false, 0); + http2TestServer = new Http2TestServer("localhost", false, 0); http2TestServer.addHandler(h2_fixedLengthHandler, "/http2/fixed"); http2TestServer.addHandler(h2_chunkedHandler, "/http2/chunk"); - int port = http2TestServer.getAddress().getPort(); - http2URI_fixed = "http://127.0.0.1:" + port + "/http2/fixed"; - http2URI_chunk = "http://127.0.0.1:" + port + "/http2/chunk"; + http2URI_fixed = "http://" + http2TestServer.serverAuthority() + "/http2/fixed"; + http2URI_chunk = "http://" + http2TestServer.serverAuthority() + "/http2/chunk"; - https2TestServer = new Http2TestServer("127.0.0.1", true, 0); + https2TestServer = new Http2TestServer("localhost", true, 0); https2TestServer.addHandler(h2_fixedLengthHandler, "/https2/fixed"); https2TestServer.addHandler(h2_chunkedHandler, "/https2/chunk"); - port = https2TestServer.getAddress().getPort(); - https2URI_fixed = "https://127.0.0.1:" + port + "/https2/fixed"; - https2URI_chunk = "https://127.0.0.1:" + port + "/https2/chunk"; + https2URI_fixed = "https://" + https2TestServer.serverAuthority() + "/https2/fixed"; + https2URI_chunk = "https://" + https2TestServer.serverAuthority() + "/https2/chunk"; httpTestServer.start(); httpsTestServer.start(); diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/ImmutableHeaders.java --- a/test/jdk/java/net/httpclient/ImmutableHeaders.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/ImmutableHeaders.java Thu Mar 08 17:42:16 2018 +0000 @@ -37,6 +37,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.URI; import java.net.http.HttpClient; @@ -54,7 +55,8 @@ final static String RESPONSE = "Hello world"; public static void main(String[] args) throws Exception { - HttpServer server = HttpServer.create(new InetSocketAddress(0), 10); + InetSocketAddress addr = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0); + HttpServer server = HttpServer.create(addr, 10); ExecutorService serverExecutor = Executors.newCachedThreadPool(); ExecutorService clientExecutor = Executors.newCachedThreadPool(); server.createContext("/test", new ImmutableHeadersHandler()); @@ -68,7 +70,7 @@ .build(); try { - URI uri = new URI("http://127.0.0.1:" + port + "/test/foo"); + URI uri = new URI("http://localhost:" + port + "/test/foo"); HttpRequest req = HttpRequest.newBuilder(uri) .headers("X-Foo", "bar") .headers("X-Bar", "foo") diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/InterruptedBlockingSend.java --- a/test/jdk/java/net/httpclient/InterruptedBlockingSend.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/InterruptedBlockingSend.java Thu Mar 08 17:42:16 2018 +0000 @@ -21,6 +21,7 @@ * questions. */ +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.ServerSocket; import java.net.URI; @@ -43,9 +44,9 @@ HttpClient client = HttpClient.newHttpClient(); try (ServerSocket ss = new ServerSocket()) { ss.setReuseAddress(false); - ss.bind(new InetSocketAddress(0)); + ss.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0)); int port = ss.getLocalPort(); - URI uri = new URI("http://127.0.0.1:" + port + "/"); + URI uri = new URI("http://localhost:" + port + "/"); HttpRequest request = HttpRequest.newBuilder(uri).build(); diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/InvalidSSLContextTest.java --- a/test/jdk/java/net/httpclient/InvalidSSLContextTest.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/InvalidSSLContextTest.java Thu Mar 08 17:42:16 2018 +0000 @@ -32,6 +32,7 @@ import java.io.IOException; import java.io.UncheckedIOException; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.URI; import java.util.concurrent.CompletableFuture; @@ -144,7 +145,8 @@ .getServerSocketFactory() .createServerSocket(); sslServerSocket.setReuseAddress(false); - sslServerSocket.bind(new InetSocketAddress(0)); + InetSocketAddress addr = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0); + sslServerSocket.bind(addr); uri = "https://localhost:" + sslServerSocket.getLocalPort() + "/"; Thread t = new Thread("SSL-Server-Side") { diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/LightWeightHttpServer.java --- a/test/jdk/java/net/httpclient/LightWeightHttpServer.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/LightWeightHttpServer.java Thu Mar 08 17:42:16 2018 +0000 @@ -38,6 +38,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.nio.file.Path; import java.util.HashSet; @@ -81,7 +82,7 @@ logger.addHandler(ch); String root = System.getProperty("test.src", ".") + "/docs"; - InetSocketAddress addr = new InetSocketAddress(0); + InetSocketAddress addr = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0); httpServer = HttpServer.create(addr, 0); if (httpServer instanceof HttpsServer) { throw new RuntimeException("should not be httpsserver"); @@ -118,8 +119,8 @@ System.out.println("HTTP server port = " + port); httpsport = httpsServer.getAddress().getPort(); System.out.println("HTTPS server port = " + httpsport); - httproot = "http://127.0.0.1:" + port + "/"; - httpsroot = "https://127.0.0.1:" + httpsport + "/"; + httproot = "http://localhost:" + port + "/"; + httpsroot = "https://localhost:" + httpsport + "/"; proxy = new ProxyServer(0, false); proxyPort = proxy.getPort(); diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/LineBodyHandlerTest.java --- a/test/jdk/java/net/httpclient/LineBodyHandlerTest.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/LineBodyHandlerTest.java Thu Mar 08 17:42:16 2018 +0000 @@ -28,6 +28,7 @@ import java.io.StringReader; import java.io.UncheckedIOException; import java.math.BigInteger; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.URI; import java.net.http.HttpClient; @@ -645,28 +646,24 @@ if (sslContext == null) throw new AssertionError("Unexpected null sslContext"); - InetSocketAddress sa = new InetSocketAddress(0); + InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0); httpTestServer = HttpTestServer.of(HttpServer.create(sa, 0)); httpTestServer.addHandler(new HttpTestEchoHandler(), "/http1/echo"); - int port = httpTestServer.getAddress().getPort(); - httpURI = "http://127.0.0.1:" + port + "/http1/echo"; + httpURI = "http://" + httpTestServer.serverAuthority() + "/http1/echo"; HttpsServer httpsServer = HttpsServer.create(sa, 0); httpsServer.setHttpsConfigurator(new HttpsConfigurator(sslContext)); httpsTestServer = HttpTestServer.of(httpsServer); httpsTestServer.addHandler(new HttpTestEchoHandler(),"/https1/echo"); - port = httpsTestServer.getAddress().getPort(); - httpsURI = "https://127.0.0.1:" + port + "/https1/echo"; + httpsURI = "https://" + httpsTestServer.serverAuthority() + "/https1/echo"; - http2TestServer = HttpTestServer.of(new Http2TestServer("127.0.0.1", false, 0)); + http2TestServer = HttpTestServer.of(new Http2TestServer("localhost", false, 0)); http2TestServer.addHandler(new HttpTestEchoHandler(), "/http2/echo"); - port = http2TestServer.getAddress().getPort(); - http2URI = "http://127.0.0.1:" + port + "/http2/echo"; + http2URI = "http://" + http2TestServer.serverAuthority() + "/http2/echo"; - https2TestServer = HttpTestServer.of(new Http2TestServer("127.0.0.1", true, 0)); + https2TestServer = HttpTestServer.of(new Http2TestServer("localhost", true, 0)); https2TestServer.addHandler(new HttpTestEchoHandler(), "/https2/echo"); - port = https2TestServer.getAddress().getPort(); - https2URI = "https://127.0.0.1:" + port + "/https2/echo"; + https2URI = "https://" + https2TestServer.serverAuthority() + "/https2/echo"; httpTestServer.start(); httpsTestServer.start(); diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/ManyRequests.java --- a/test/jdk/java/net/httpclient/ManyRequests.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/ManyRequests.java Thu Mar 08 17:42:16 2018 +0000 @@ -47,6 +47,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.URI; import java.net.http.HttpClient; @@ -78,7 +79,7 @@ + ", XFixed=" + XFIXED); SSLContext ctx = new SimpleSSLContext().get(); - InetSocketAddress addr = new InetSocketAddress(0); + InetSocketAddress addr = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0); HttpsServer server = HttpsServer.create(addr, 0); server.setHttpsConfigurator(new Configurator(ctx)); @@ -129,7 +130,7 @@ static void test(HttpsServer server, HttpClient client) throws Exception { int port = server.getAddress().getPort(); - URI baseURI = new URI("https://127.0.0.1:" + port + "/foo/x"); + URI baseURI = new URI("https://localhost:" + port + "/foo/x"); server.createContext("/foo", new TestEchoHandler()); server.start(); diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/ManyRequestsLegacy.java --- a/test/jdk/java/net/httpclient/ManyRequestsLegacy.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/ManyRequestsLegacy.java Thu Mar 08 17:42:16 2018 +0000 @@ -48,6 +48,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.HttpURLConnection; +import java.net.InetAddress; import java.net.URI; import java.net.URLConnection; import java.util.Optional; @@ -90,7 +91,7 @@ return true; } }); - InetSocketAddress addr = new InetSocketAddress(0); + InetSocketAddress addr = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0); HttpsServer server = HttpsServer.create(addr, 0); server.setHttpsConfigurator(new Configurator(ctx)); @@ -217,7 +218,7 @@ static void test(HttpsServer server, LegacyHttpClient client) throws Exception { int port = server.getAddress().getPort(); - URI baseURI = new URI("https://127.0.0.1:" + port + "/foo/x"); + URI baseURI = new URI("https://localhost:" + port + "/foo/x"); server.createContext("/foo", new TestEchoHandler()); server.start(); diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/MappingResponseSubscriber.java --- a/test/jdk/java/net/httpclient/MappingResponseSubscriber.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/MappingResponseSubscriber.java Thu Mar 08 17:42:16 2018 +0000 @@ -38,6 +38,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.URI; import java.nio.ByteBuffer; @@ -185,6 +186,10 @@ } } + static String serverAuthority(HttpServer server) { + return InetAddress.getLoopbackAddress().getHostName() + ":" + + server.getAddress().getPort(); + } @BeforeTest public void setup() throws Exception { @@ -195,37 +200,35 @@ // HTTP/1.1 HttpHandler h1_fixedLengthHandler = new HTTP1_FixedLengthHandler(); HttpHandler h1_chunkHandler = new HTTP1_ChunkedHandler(); - InetSocketAddress sa = new InetSocketAddress("localhost", 0); + InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0); httpTestServer = HttpServer.create(sa, 0); httpTestServer.createContext("/http1/fixed", h1_fixedLengthHandler); httpTestServer.createContext("/http1/chunk", h1_chunkHandler); - httpURI_fixed = "http://127.0.0.1:" + httpTestServer.getAddress().getPort() + "/http1/fixed"; - httpURI_chunk = "http://127.0.0.1:" + httpTestServer.getAddress().getPort() + "/http1/chunk"; + httpURI_fixed = "http://" + serverAuthority(httpTestServer) + "/http1/fixed"; + httpURI_chunk = "http://" + serverAuthority(httpTestServer) + "/http1/chunk"; httpsTestServer = HttpsServer.create(sa, 0); httpsTestServer.setHttpsConfigurator(new HttpsConfigurator(sslContext)); httpsTestServer.createContext("/https1/fixed", h1_fixedLengthHandler); httpsTestServer.createContext("/https1/chunk", h1_chunkHandler); - httpsURI_fixed = "https://127.0.0.1:" + httpsTestServer.getAddress().getPort() + "/https1/fixed"; - httpsURI_chunk = "https://127.0.0.1:" + httpsTestServer.getAddress().getPort() + "/https1/chunk"; + httpsURI_fixed = "https://" + serverAuthority(httpsTestServer) + "/https1/fixed"; + httpsURI_chunk = "https://" + serverAuthority(httpsTestServer) + "/https1/chunk"; // HTTP/2 Http2Handler h2_fixedLengthHandler = new HTTP2_FixedLengthHandler(); Http2Handler h2_chunkedHandler = new HTTP2_VariableHandler(); - http2TestServer = new Http2TestServer("127.0.0.1", false, 0); + http2TestServer = new Http2TestServer("localhost", false, 0); http2TestServer.addHandler(h2_fixedLengthHandler, "/http2/fixed"); http2TestServer.addHandler(h2_chunkedHandler, "/http2/chunk"); - int port = http2TestServer.getAddress().getPort(); - http2URI_fixed = "http://127.0.0.1:" + port + "/http2/fixed"; - http2URI_chunk = "http://127.0.0.1:" + port + "/http2/chunk"; + http2URI_fixed = "http://" + http2TestServer.serverAuthority() + "/http2/fixed"; + http2URI_chunk = "http://" + http2TestServer.serverAuthority() + "/http2/chunk"; - https2TestServer = new Http2TestServer("127.0.0.1", true, 0); + https2TestServer = new Http2TestServer("localhost", true, 0); https2TestServer.addHandler(h2_fixedLengthHandler, "/https2/fixed"); https2TestServer.addHandler(h2_chunkedHandler, "/https2/chunk"); - port = https2TestServer.getAddress().getPort(); - https2URI_fixed = "https://127.0.0.1:" + port + "/https2/fixed"; - https2URI_chunk = "https://127.0.0.1:" + port + "/https2/chunk"; + https2URI_fixed = "https://" + https2TestServer.serverAuthority() + "/https2/fixed"; + https2URI_chunk = "https://" + https2TestServer.serverAuthority() + "/https2/chunk"; httpTestServer.start(); httpsTestServer.start(); diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/MockServer.java --- a/test/jdk/java/net/httpclient/MockServer.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/MockServer.java Thu Mar 08 17:42:16 2018 +0000 @@ -21,12 +21,15 @@ * questions. */ +import com.sun.net.httpserver.HttpServer; + import java.io.Closeable; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import javax.net.ServerSocketFactory; import javax.net.ssl.SSLServerSocket; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.ServerSocket; import java.net.Socket; @@ -290,7 +293,7 @@ MockServer(int port, ServerSocketFactory factory, String root) throws IOException { ss = factory.createServerSocket(); ss.setReuseAddress(false); - ss.bind(new InetSocketAddress(0)); + ss.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0)); this.root = root; // if specified, any request which don't have this value // in their statusLine will be rejected. sockets = Collections.synchronizedList(new LinkedList<>()); @@ -316,11 +319,15 @@ return ss.getLocalPort(); } + String serverAuthority() { + return InetAddress.getLoopbackAddress().getHostName() + ":" + port(); + } + public String getURL() { if (ss instanceof SSLServerSocket) { - return "https://127.0.0.1:" + port() + "/foo/"; + return "https://" + serverAuthority() + "/foo/"; } else { - return "http://127.0.0.1:" + port() + "/foo/"; + return "http://" + serverAuthority() + "/foo/"; } } diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/MultiAuthTest.java --- a/test/jdk/java/net/httpclient/MultiAuthTest.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/MultiAuthTest.java Thu Mar 08 17:42:16 2018 +0000 @@ -39,6 +39,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.PasswordAuthentication; import java.net.URI; @@ -61,7 +62,8 @@ static final String POST_BODY = "This is the POST body " + UUID.randomUUID(); static HttpServer createServer(ExecutorService e, BasicAuthenticator sa) throws Exception { - HttpServer server = HttpServer.create(new InetSocketAddress(0), 10); + InetSocketAddress addr = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0); + HttpServer server = HttpServer.create(addr, 10); Handler h = new Handler(); HttpContext serverContext = server.createContext("/test", h); serverContext.setAuthenticator(sa); @@ -95,7 +97,7 @@ HttpClient client3 = HttpClient.newHttpClient(); try { - URI uri = new URI("http://127.0.0.1:" + port + "/test/foo"); + URI uri = new URI("http://localhost:" + port + "/test/foo"); System.out.println("URI: " + uri); System.out.println("\nTesting with client #1, Authenticator #1"); diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/ProxyAuthTest.java --- a/test/jdk/java/net/httpclient/ProxyAuthTest.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/ProxyAuthTest.java Thu Mar 08 17:42:16 2018 +0000 @@ -39,6 +39,7 @@ import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.net.Authenticator; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.PasswordAuthentication; import java.net.Proxy; @@ -62,14 +63,14 @@ public static void main(String[] args) throws Exception { try (ServerSocket ss = new ServerSocket()) { ss.setReuseAddress(false); - ss.bind(new InetSocketAddress(0)); + ss.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0)); int port = ss.getLocalPort(); MyProxy proxy = new MyProxy(ss); (new Thread(proxy)).start(); System.out.println("Proxy listening port " + port); Auth auth = new Auth(); - InetSocketAddress paddr = new InetSocketAddress("localhost", port); + InetSocketAddress paddr = new InetSocketAddress(InetAddress.getLoopbackAddress(), port); URI uri = new URI("http://www.google.ie/"); CountingProxySelector ps = CountingProxySelector.of(paddr); diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/ProxyServer.java --- a/test/jdk/java/net/httpclient/ProxyServer.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/ProxyServer.java Thu Mar 08 17:42:16 2018 +0000 @@ -50,7 +50,7 @@ this.debug = debug; listener = new ServerSocket(); listener.setReuseAddress(false); - listener.bind(new InetSocketAddress(port)); + listener.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), port)); this.port = listener.getLocalPort(); setName("ProxyListener"); setDaemon(true); diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/ProxyTest.java --- a/test/jdk/java/net/httpclient/ProxyTest.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/ProxyTest.java Thu Mar 08 17:42:16 2018 +0000 @@ -104,7 +104,8 @@ }); server.setHttpsConfigurator(new Configurator(SSLContext.getDefault())); - server.bind(new InetSocketAddress(0), 0); + InetSocketAddress addr = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0); + server.bind(addr, 0); return server; } @@ -242,7 +243,7 @@ } void start() throws IOException { - ss.bind(new InetSocketAddress(0)); + ss.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0)); accept.start(); } @@ -276,9 +277,8 @@ } public InetSocketAddress getAddress() { - return new InetSocketAddress( - "localhost", - ss.getLocalPort()); + return new InetSocketAddress(InetAddress.getLoopbackAddress(), + ss.getLocalPort()); } // This is a bit shaky. It doesn't handle continuation diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/RedirectWithCookie.java --- a/test/jdk/java/net/httpclient/RedirectWithCookie.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/RedirectWithCookie.java Thu Mar 08 17:42:16 2018 +0000 @@ -164,10 +164,10 @@ httpsTestServer.addHandler(new CookieRedirectHandler(),"/https1/cookie/"); httpsURI = "https://" + httpsTestServer.serverAuthority() + "/https1/cookie/redirect"; - http2TestServer = HttpTestServer.of(new Http2TestServer("127.0.0.1", false, 0)); + http2TestServer = HttpTestServer.of(new Http2TestServer("localhost", false, 0)); http2TestServer.addHandler(new CookieRedirectHandler(), "/http2/cookie/"); http2URI = "http://" + http2TestServer.serverAuthority() + "/http2/cookie/redirect"; - https2TestServer = HttpTestServer.of(new Http2TestServer("127.0.0.1", true, 0)); + https2TestServer = HttpTestServer.of(new Http2TestServer("localhost", true, 0)); https2TestServer.addHandler(new CookieRedirectHandler(), "/https2/cookie/"); https2URI = "https://" + https2TestServer.serverAuthority() + "/https2/cookie/redirect"; diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/RequestBodyTest.policy --- a/test/jdk/java/net/httpclient/RequestBodyTest.policy Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/RequestBodyTest.policy Thu Mar 08 17:42:16 2018 +0000 @@ -38,14 +38,14 @@ permission java.io.FilePermission "${test.src}${/}docs${/}files${/}notsobigfile.txt", "read"; permission java.io.FilePermission "RequestBodyTest.tmp", "read,write,delete"; - permission java.net.URLPermission "http://127.0.0.1:*/echo/foo", "POST"; - permission java.net.URLPermission "https://127.0.0.1:*/echo/foo", "POST"; + permission java.net.URLPermission "http://localhost:*/echo/foo", "POST"; + permission java.net.URLPermission "https://localhost:*/echo/foo", "POST"; // for HTTP/1.1 server logging permission java.util.logging.LoggingPermission "control"; // needed to grant the HTTP server - permission java.net.SocketPermission "127.0.0.1:*", "accept,resolve"; + permission java.net.SocketPermission "localhost:*", "accept,resolve"; permission java.util.PropertyPermission "*", "read"; permission java.lang.RuntimePermission "modifyThread"; diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/RequestBuilderTest.java --- a/test/jdk/java/net/httpclient/RequestBuilderTest.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/RequestBuilderTest.java Thu Mar 08 17:42:16 2018 +0000 @@ -327,7 +327,7 @@ @Test public void testRestricted() throws URISyntaxException { - URI uri = new URI("http://127.0.0.1:80/test/"); + URI uri = new URI("http://localhost:80/test/"); Map lambdas = Map.of( "Builder::header", HttpRequest.Builder::header, "Builder::headers", (b, n, v) -> b.headers(n,v), diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/ShortRequestBody.java --- a/test/jdk/java/net/httpclient/ShortRequestBody.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/ShortRequestBody.java Thu Mar 08 17:42:16 2018 +0000 @@ -25,6 +25,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.UncheckedIOException; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.ServerSocket; import java.net.Socket; @@ -133,7 +134,7 @@ try (Server server = new Server()) { for (Supplier cs : clientSuppliers) { err.println("\n---- next supplier ----\n"); - URI uri = new URI("http://127.0.0.1:" + server.getPort() + "/"); + URI uri = new URI("http://localhost:" + server.getPort() + "/"); // sanity ( 6 requests to keep client and server offsets easy to workout ) success(cs, uri, new StringRequestBody(STRING_BODY, 0)); @@ -235,7 +236,7 @@ super("Test-Server"); ss = new ServerSocket(); ss.setReuseAddress(false); - ss.bind(new InetSocketAddress(0)); + ss.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0)); this.start(); } diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/SmallTimeout.java --- a/test/jdk/java/net/httpclient/SmallTimeout.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/SmallTimeout.java Thu Mar 08 17:42:16 2018 +0000 @@ -22,6 +22,7 @@ */ import java.io.IOException; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.ServerSocket; import java.net.URI; @@ -80,9 +81,9 @@ try (ServerSocket ss = new ServerSocket()) { ss.setReuseAddress(false); - ss.bind(new InetSocketAddress(0)); + ss.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0)); int port = ss.getLocalPort(); - URI uri = new URI("http://127.0.0.1:" + port + "/"); + URI uri = new URI("http://localhost:" + port + "/"); HttpRequest[] requests = new HttpRequest[TIMEOUTS.length]; diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/SmokeTest.java --- a/test/jdk/java/net/httpclient/SmokeTest.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/SmokeTest.java Thu Mar 08 17:42:16 2018 +0000 @@ -46,6 +46,8 @@ import com.sun.net.httpserver.HttpsConfigurator; import com.sun.net.httpserver.HttpsParameters; import com.sun.net.httpserver.HttpsServer; + +import java.net.InetAddress; import java.net.Proxy; import java.net.SocketAddress; import java.util.Collections; @@ -450,7 +452,8 @@ static void test4(String s) throws Exception { System.out.print("test4: " + s); URI uri = new URI(s); - InetSocketAddress proxyAddr = new InetSocketAddress("127.0.0.1", proxyPort); + InetSocketAddress proxyAddr = new InetSocketAddress(InetAddress.getLoopbackAddress(), + proxyPort); String filename = fileroot + uri.getPath(); ExecutorService e = Executors.newCachedThreadPool(); @@ -726,7 +729,7 @@ logger.addHandler(ch); String root = System.getProperty ("test.src", ".")+ "/docs"; - InetSocketAddress addr = new InetSocketAddress (0); + InetSocketAddress addr = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0); s1 = HttpServer.create (addr, 0); if (s1 instanceof HttpsServer) { throw new RuntimeException ("should not be httpsserver"); @@ -765,8 +768,8 @@ System.out.println("HTTP server port = " + port); httpsport = s2.getAddress().getPort(); System.out.println("HTTPS server port = " + httpsport); - httproot = "http://127.0.0.1:" + port + "/"; - httpsroot = "https://127.0.0.1:" + httpsport + "/"; + httproot = "http://localhost:" + port + "/"; + httpsroot = "https://localhost:" + httpsport + "/"; proxy = new ProxyServer(0, false); proxyPort = proxy.getPort(); diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/ThrowingPublishers.java --- a/test/jdk/java/net/httpclient/ThrowingPublishers.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/ThrowingPublishers.java Thu Mar 08 17:42:16 2018 +0000 @@ -23,7 +23,7 @@ /* * @test - * @summary Tests what happens when request publishers + * @summary Tests what happens when request publishers * throw unexpected exceptions. * @library /lib/testlibrary http2/server * @build jdk.testlibrary.SimpleSSLContext HttpServerAdapters ThrowingPublishers @@ -51,6 +51,7 @@ import java.io.InputStreamReader; import java.io.OutputStream; import java.io.UncheckedIOException; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.URI; import java.net.http.HttpClient; @@ -579,38 +580,36 @@ // HTTP/1.1 HttpTestHandler h1_fixedLengthHandler = new HTTP_FixedLengthHandler(); HttpTestHandler h1_chunkHandler = new HTTP_ChunkedHandler(); - InetSocketAddress sa = new InetSocketAddress(0); + InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0); httpTestServer = HttpTestServer.of(HttpServer.create(sa, 0)); httpTestServer.addHandler(h1_fixedLengthHandler, "/http1/fixed"); httpTestServer.addHandler(h1_chunkHandler, "/http1/chunk"); - httpURI_fixed = "http://127.0.0.1:" + httpTestServer.getAddress().getPort() + "/http1/fixed/x"; - httpURI_chunk = "http://127.0.0.1:" + httpTestServer.getAddress().getPort() + "/http1/chunk/x"; + httpURI_fixed = "http://" + httpTestServer.serverAuthority() + "/http1/fixed/x"; + httpURI_chunk = "http://" + httpTestServer.serverAuthority() + "/http1/chunk/x"; HttpsServer httpsServer = HttpsServer.create(sa, 0); httpsServer.setHttpsConfigurator(new HttpsConfigurator(sslContext)); httpsTestServer = HttpTestServer.of(httpsServer); httpsTestServer.addHandler(h1_fixedLengthHandler, "/https1/fixed"); httpsTestServer.addHandler(h1_chunkHandler, "/https1/chunk"); - httpsURI_fixed = "https://127.0.0.1:" + httpsTestServer.getAddress().getPort() + "/https1/fixed/x"; - httpsURI_chunk = "https://127.0.0.1:" + httpsTestServer.getAddress().getPort() + "/https1/chunk/x"; + httpsURI_fixed = "https://" + httpsTestServer.serverAuthority() + "/https1/fixed/x"; + httpsURI_chunk = "https://" + httpsTestServer.serverAuthority() + "/https1/chunk/x"; // HTTP/2 HttpTestHandler h2_fixedLengthHandler = new HTTP_FixedLengthHandler(); HttpTestHandler h2_chunkedHandler = new HTTP_ChunkedHandler(); - http2TestServer = HttpTestServer.of(new Http2TestServer("127.0.0.1", false, 0)); + http2TestServer = HttpTestServer.of(new Http2TestServer("localhost", false, 0)); http2TestServer.addHandler(h2_fixedLengthHandler, "/http2/fixed"); http2TestServer.addHandler(h2_chunkedHandler, "/http2/chunk"); - int port = http2TestServer.getAddress().getPort(); - http2URI_fixed = "http://127.0.0.1:" + port + "/http2/fixed/x"; - http2URI_chunk = "http://127.0.0.1:" + port + "/http2/chunk/x"; + http2URI_fixed = "http://" + http2TestServer.serverAuthority() + "/http2/fixed/x"; + http2URI_chunk = "http://" + http2TestServer.serverAuthority() + "/http2/chunk/x"; - https2TestServer = HttpTestServer.of(new Http2TestServer("127.0.0.1", true, 0)); + https2TestServer = HttpTestServer.of(new Http2TestServer("localhost", true, 0)); https2TestServer.addHandler(h2_fixedLengthHandler, "/https2/fixed"); https2TestServer.addHandler(h2_chunkedHandler, "/https2/chunk"); - port = https2TestServer.getAddress().getPort(); - https2URI_fixed = "https://127.0.0.1:" + port + "/https2/fixed/x"; - https2URI_chunk = "https://127.0.0.1:" + port + "/https2/chunk/x"; + https2URI_fixed = "https://" + https2TestServer.serverAuthority() + "/https2/fixed/x"; + https2URI_chunk = "https://" + https2TestServer.serverAuthority() + "/https2/chunk/x"; serverCount.addAndGet(4); httpTestServer.start(); diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/ThrowingSubscribers.java --- a/test/jdk/java/net/httpclient/ThrowingSubscribers.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/ThrowingSubscribers.java Thu Mar 08 17:42:16 2018 +0000 @@ -51,6 +51,7 @@ import java.io.InputStreamReader; import java.io.OutputStream; import java.io.UncheckedIOException; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.URI; import java.net.http.HttpClient; @@ -599,38 +600,36 @@ // HTTP/1.1 HttpTestHandler h1_fixedLengthHandler = new HTTP_FixedLengthHandler(); HttpTestHandler h1_chunkHandler = new HTTP_ChunkedHandler(); - InetSocketAddress sa = new InetSocketAddress(0); + InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0); httpTestServer = HttpTestServer.of(HttpServer.create(sa, 0)); httpTestServer.addHandler(h1_fixedLengthHandler, "/http1/fixed"); httpTestServer.addHandler(h1_chunkHandler, "/http1/chunk"); - httpURI_fixed = "http://127.0.0.1:" + httpTestServer.getAddress().getPort() + "/http1/fixed/x"; - httpURI_chunk = "http://127.0.0.1:" + httpTestServer.getAddress().getPort() + "/http1/chunk/x"; + httpURI_fixed = "http://" + httpTestServer.serverAuthority() + "/http1/fixed/x"; + httpURI_chunk = "http://" + httpTestServer.serverAuthority() + "/http1/chunk/x"; HttpsServer httpsServer = HttpsServer.create(sa, 0); httpsServer.setHttpsConfigurator(new HttpsConfigurator(sslContext)); httpsTestServer = HttpTestServer.of(httpsServer); httpsTestServer.addHandler(h1_fixedLengthHandler, "/https1/fixed"); httpsTestServer.addHandler(h1_chunkHandler, "/https1/chunk"); - httpsURI_fixed = "https://127.0.0.1:" + httpsTestServer.getAddress().getPort() + "/https1/fixed/x"; - httpsURI_chunk = "https://127.0.0.1:" + httpsTestServer.getAddress().getPort() + "/https1/chunk/x"; + httpsURI_fixed = "https://" + httpsTestServer.serverAuthority() + "/https1/fixed/x"; + httpsURI_chunk = "https://" + httpsTestServer.serverAuthority() + "/https1/chunk/x"; // HTTP/2 HttpTestHandler h2_fixedLengthHandler = new HTTP_FixedLengthHandler(); HttpTestHandler h2_chunkedHandler = new HTTP_ChunkedHandler(); - http2TestServer = HttpTestServer.of(new Http2TestServer("127.0.0.1", false, 0)); + http2TestServer = HttpTestServer.of(new Http2TestServer("localhost", false, 0)); http2TestServer.addHandler(h2_fixedLengthHandler, "/http2/fixed"); http2TestServer.addHandler(h2_chunkedHandler, "/http2/chunk"); - int port = http2TestServer.getAddress().getPort(); - http2URI_fixed = "http://127.0.0.1:" + port + "/http2/fixed/x"; - http2URI_chunk = "http://127.0.0.1:" + port + "/http2/chunk/x"; + http2URI_fixed = "http://" + http2TestServer.serverAuthority() + "/http2/fixed/x"; + http2URI_chunk = "http://" + http2TestServer.serverAuthority() + "/http2/chunk/x"; - https2TestServer = HttpTestServer.of(new Http2TestServer("127.0.0.1", true, 0)); + https2TestServer = HttpTestServer.of(new Http2TestServer("localhost", true, 0)); https2TestServer.addHandler(h2_fixedLengthHandler, "/https2/fixed"); https2TestServer.addHandler(h2_chunkedHandler, "/https2/chunk"); - port = https2TestServer.getAddress().getPort(); - https2URI_fixed = "https://127.0.0.1:" + port + "/https2/fixed/x"; - https2URI_chunk = "https://127.0.0.1:" + port + "/https2/chunk/x"; + https2URI_fixed = "https://" + https2TestServer.serverAuthority() + "/https2/fixed/x"; + https2URI_chunk = "https://" + https2TestServer.serverAuthority() + "/https2/chunk/x"; serverCount.addAndGet(4); httpTestServer.start(); diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/TimeoutBasic.java --- a/test/jdk/java/net/httpclient/TimeoutBasic.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/TimeoutBasic.java Thu Mar 08 17:42:16 2018 +0000 @@ -22,6 +22,7 @@ */ import java.io.IOException; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.ServerSocket; import java.net.URI; @@ -143,9 +144,9 @@ out.printf("%ntest(version=%s, reqVersion=%s, scheme=%s)%n", version, reqVersion, scheme); try (ServerSocket ss = ssf.createServerSocket()) { ss.setReuseAddress(false); - ss.bind(new InetSocketAddress(0)); + ss.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0)); int port = ss.getLocalPort(); - URI uri = new URI(scheme +"://127.0.0.1:" + port + "/"); + URI uri = new URI(scheme +"://localhost:" + port + "/"); out.println("--- TESTING Async"); int count = 0; diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/TimeoutOrdering.java --- a/test/jdk/java/net/httpclient/TimeoutOrdering.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/TimeoutOrdering.java Thu Mar 08 17:42:16 2018 +0000 @@ -22,6 +22,7 @@ */ import java.io.IOException; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.ServerSocket; import java.net.URI; @@ -62,9 +63,9 @@ try (ServerSocket ss = new ServerSocket()) { ss.setReuseAddress(false); - ss.bind(new InetSocketAddress(0)); + ss.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0)); int port = ss.getLocalPort(); - URI uri = new URI("http://127.0.0.1:" + port + "/"); + URI uri = new URI("http://localhost:" + port + "/"); HttpRequest[] requests = new HttpRequest[TIMEOUTS.length]; diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/VersionTest.java --- a/test/jdk/java/net/httpclient/VersionTest.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/VersionTest.java Thu Mar 08 17:42:16 2018 +0000 @@ -37,6 +37,7 @@ import com.sun.net.httpserver.HttpServer; import java.io.IOException; import java.io.OutputStream; +import java.net.InetAddress; import java.net.URI; import java.net.InetSocketAddress; import java.net.ProxySelector; @@ -102,7 +103,7 @@ } static void initServer() throws Exception { - InetSocketAddress addr = new InetSocketAddress (0); + InetSocketAddress addr = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0); s1 = HttpServer.create (addr, 0); HttpHandler h = new Handler(); @@ -113,11 +114,11 @@ s1.start(); port = s1.getAddress().getPort(); - uri = new URI("http://127.0.0.1:" + Integer.toString(port) + "/foo"); + uri = new URI("http://localhost:" + Integer.toString(port) + "/foo"); System.out.println("HTTP server port = " + port); proxy = new ProxyServer(0, false); int proxyPort = proxy.getPort(); - proxyAddr = new InetSocketAddress("127.0.0.1", proxyPort); + proxyAddr = new InetSocketAddress(InetAddress.getLoopbackAddress(), proxyPort); } static class Handler implements HttpHandler { @@ -149,4 +150,4 @@ t.close(); } } -} \ No newline at end of file +} diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/ZeroRedirects.java --- a/test/jdk/java/net/httpclient/ZeroRedirects.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/ZeroRedirects.java Thu Mar 08 17:42:16 2018 +0000 @@ -34,6 +34,7 @@ import com.sun.net.httpserver.HttpServer; import java.io.IOException; import java.io.OutputStream; +import java.net.InetAddress; import java.net.URI; import java.net.http.HttpResponse.BodyHandlers; import java.util.concurrent.Executors; @@ -77,8 +78,8 @@ } static void initServer() throws Exception { - InetSocketAddress addr = new InetSocketAddress (0); - s1 = HttpServer.create (addr, 0); + InetSocketAddress addr = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0); + s1 = HttpServer.create(addr, 0); HttpHandler h = new Handler(); HttpContext c1 = s1.createContext("/", h); @@ -88,7 +89,7 @@ s1.start(); port = s1.getAddress().getPort(); - uri = new URI("http://127.0.0.1:" + Integer.toString(port) + "/foo"); + uri = new URI("http://localhost:" + port + "/foo"); System.out.println("HTTP server port = " + port); } diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/http2/BadHeadersTest.java --- a/test/jdk/java/net/httpclient/http2/BadHeadersTest.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/http2/BadHeadersTest.java Thu Mar 08 17:42:16 2018 +0000 @@ -186,7 +186,7 @@ if (sslContext == null) throw new AssertionError("Unexpected null sslContext"); - http2TestServer = new Http2TestServer("127.0.0.1", false, 0) { + http2TestServer = new Http2TestServer("localhost", false, 0) { @Override protected Http2TestServerConnection createConnection(Http2TestServer http2TestServer, Socket socket, @@ -202,9 +202,9 @@ }; http2TestServer.addHandler(new Http2EchoHandler(), "/http2/echo"); int port = http2TestServer.getAddress().getPort(); - http2URI = "http://127.0.0.1:" + port + "/http2/echo"; + http2URI = "http://localhost:" + port + "/http2/echo"; - https2TestServer = new Http2TestServer("127.0.0.1", true, 0){ + https2TestServer = new Http2TestServer("localhost", true, 0){ @Override protected Http2TestServerConnection createConnection(Http2TestServer http2TestServer, Socket socket, @@ -220,7 +220,7 @@ }; https2TestServer.addHandler(new Http2EchoHandler(), "/https2/echo"); port = https2TestServer.getAddress().getPort(); - https2URI = "https://127.0.0.1:" + port + "/https2/echo"; + https2URI = "https://localhost:" + port + "/https2/echo"; // Override the default exchange supplier with a custom one to enable // particular test scenarios diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/http2/BasicTest.java --- a/test/jdk/java/net/httpclient/http2/BasicTest.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/http2/BasicTest.java Thu Mar 08 17:42:16 2018 +0000 @@ -76,9 +76,9 @@ httpsServer.addHandler(new Http2EchoHandler(), "/"); httpsPort = httpsServer.getAddress().getPort(); - httpURIString = "http://127.0.0.1:" + httpPort + "/foo/"; - pingURIString = "http://127.0.0.1:" + httpPort + "/ping/"; - httpsURIString = "https://127.0.0.1:" + httpsPort + "/bar/"; + httpURIString = "http://localhost:" + httpPort + "/foo/"; + pingURIString = "http://localhost:" + httpPort + "/ping/"; + httpsURIString = "https://localhost:" + httpsPort + "/bar/"; httpServer.start(); httpsServer.start(); @@ -229,7 +229,7 @@ t.sendResponseHeaders(500, -1); } }), "/"); - URI u = new URI("https://127.0.0.1:"+httpsPort+"/foo"); + URI u = new URI("https://localhost:"+httpsPort+"/foo"); HttpClient client = getClient(); HttpRequest req = HttpRequest.newBuilder(u).build(); HttpResponse resp = client.send(req, BodyHandlers.ofString()); diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/http2/ContinuationFrameTest.java --- a/test/jdk/java/net/httpclient/http2/ContinuationFrameTest.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/http2/ContinuationFrameTest.java Thu Mar 08 17:42:16 2018 +0000 @@ -163,15 +163,15 @@ if (sslContext == null) throw new AssertionError("Unexpected null sslContext"); - http2TestServer = new Http2TestServer("127.0.0.1", false, 0); + http2TestServer = new Http2TestServer("localhost", false, 0); http2TestServer.addHandler(new Http2EchoHandler(), "/http2/echo"); int port = http2TestServer.getAddress().getPort(); - http2URI = "http://127.0.0.1:" + port + "/http2/echo"; + http2URI = "http://localhost:" + port + "/http2/echo"; - https2TestServer = new Http2TestServer("127.0.0.1", true, 0); + https2TestServer = new Http2TestServer("localhost", true, 0); https2TestServer.addHandler(new Http2EchoHandler(), "/https2/echo"); port = https2TestServer.getAddress().getPort(); - https2URI = "https://127.0.0.1:" + port + "/https2/echo"; + https2URI = "https://localhost:" + port + "/https2/echo"; // Override the default exchange supplier with a custom one to enable // particular test scenarios diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/http2/ErrorTest.java --- a/test/jdk/java/net/httpclient/http2/ErrorTest.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/http2/ErrorTest.java Thu Mar 08 17:42:16 2018 +0000 @@ -85,7 +85,7 @@ serverContext); httpsServer.addHandler(new Http2EchoHandler(), "/"); int httpsPort = httpsServer.getAddress().getPort(); - String httpsURIString = "https://127.0.0.1:" + httpsPort + "/bar/"; + String httpsURIString = "https://localhost:" + httpsPort + "/bar/"; httpsServer.start(); URI uri = URI.create(httpsURIString); diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/http2/FixedThreadPoolTest.java --- a/test/jdk/java/net/httpclient/http2/FixedThreadPoolTest.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/http2/FixedThreadPoolTest.java Thu Mar 08 17:42:16 2018 +0000 @@ -67,8 +67,8 @@ httpsServer.addHandler(new Http2EchoHandler(), "/"); httpsPort = httpsServer.getAddress().getPort(); - httpURIString = "http://127.0.0.1:" + httpPort + "/foo/"; - httpsURIString = "https://127.0.0.1:" + httpsPort + "/bar/"; + httpURIString = "http://localhost:" + httpPort + "/foo/"; + httpsURIString = "https://localhost:" + httpsPort + "/bar/"; httpServer.start(); httpsServer.start(); @@ -192,7 +192,7 @@ }), "/"); server.start(); int port = server.getAddress().getPort(); - URI u = new URI("https://127.0.0.1:"+port+"/foo"); + URI u = new URI("https://localhost:"+port+"/foo"); HttpClient client = getClient(); HttpRequest req = HttpRequest.newBuilder(u).build(); HttpResponse resp = client.sendAsync(req, BodyHandlers.ofString()).get(); diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/http2/ImplicitPushCancel.java --- a/test/jdk/java/net/httpclient/http2/ImplicitPushCancel.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/http2/ImplicitPushCancel.java Thu Mar 08 17:42:16 2018 +0000 @@ -85,7 +85,7 @@ server.start(); int port = server.getAddress().getPort(); System.err.println("Server listening on port " + port); - uri = new URI("http://127.0.0.1:" + port + "/foo/a/b/c"); + uri = new URI("http://localhost:" + port + "/foo/a/b/c"); } @AfterTest diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/http2/ProxyTest2.java --- a/test/jdk/java/net/httpclient/http2/ProxyTest2.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/http2/ProxyTest2.java Thu Mar 08 17:42:16 2018 +0000 @@ -177,7 +177,7 @@ void start() throws IOException { ss.setReuseAddress(false); - ss.bind(new InetSocketAddress(0)); + ss.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0)); accept.start(); } @@ -211,9 +211,7 @@ } public InetSocketAddress getAddress() { - return new InetSocketAddress( - "localhost", - ss.getLocalPort()); + return new InetSocketAddress( InetAddress.getLoopbackAddress(), ss.getLocalPort()); } // This is a bit shaky. It doesn't handle continuation diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/http2/RedirectTest.java --- a/test/jdk/java/net/httpclient/http2/RedirectTest.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/http2/RedirectTest.java Thu Mar 08 17:42:16 2018 +0000 @@ -101,11 +101,11 @@ // urls are accessed in sequence below. The first two are on // different servers. Third on same server as second. So, the // client should use the same http connection. - httpURIString = "http://127.0.0.1:" + httpPort + "/foo/"; + httpURIString = "http://localhost:" + httpPort + "/foo/"; httpURI = URI.create(httpURIString); - altURIString1 = "http://127.0.0.1:" + httpPort + "/redir"; + altURIString1 = "http://localhost:" + httpPort + "/redir"; altURI1 = URI.create(altURIString1); - altURIString2 = "http://127.0.0.1:" + httpPort + "/redir_again"; + altURIString2 = "http://localhost:" + httpPort + "/redir_again"; altURI2 = URI.create(altURIString2); Redirector r = new Redirector(sup(altURIString1, altURIString2)); diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/http2/ServerPush.java --- a/test/jdk/java/net/httpclient/http2/ServerPush.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/http2/ServerPush.java Thu Mar 08 17:42:16 2018 +0000 @@ -74,7 +74,7 @@ System.err.println("Server listening on port " + server.getAddress().getPort()); server.start(); int port = server.getAddress().getPort(); - uri = new URI("http://127.0.0.1:" + port + "/foo/a/b/c"); + uri = new URI("http://localhost:" + port + "/foo/a/b/c"); } @AfterTest diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/http2/ServerPushWithDiffTypes.java --- a/test/jdk/java/net/httpclient/http2/ServerPushWithDiffTypes.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/http2/ServerPushWithDiffTypes.java Thu Mar 08 17:42:16 2018 +0000 @@ -80,7 +80,7 @@ HttpClient client = HttpClient.newHttpClient(); // use multi-level path - URI uri = new URI("http://127.0.0.1:" + port + "/foo/a/b/c"); + URI uri = new URI("http://localhost:" + port + "/foo/a/b/c"); HttpRequest request = HttpRequest.newBuilder(uri).GET().build(); ConcurrentMap>>> diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/http2/TLSConnection.java --- a/test/jdk/java/net/httpclient/http2/TLSConnection.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/http2/TLSConnection.java Thu Mar 08 17:42:16 2018 +0000 @@ -69,12 +69,12 @@ Handler handler = new Handler(); - try (Http2TestServer server = new Http2TestServer("127.0.0.1", true, 0)) { + try (Http2TestServer server = new Http2TestServer("localhost", true, 0)) { server.addHandler(handler, "/"); server.start(); int port = server.getAddress().getPort(); - String uriString = "https://127.0.0.1:" + Integer.toString(port); + String uriString = "https://localhost:" + Integer.toString(port); // run test cases boolean success = true; diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/http2/Timeout.java --- a/test/jdk/java/net/httpclient/http2/Timeout.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/http2/Timeout.java Thu Mar 08 17:42:16 2018 +0000 @@ -23,6 +23,7 @@ import java.io.File; import java.io.IOException; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.URI; import java.net.http.HttpClient; @@ -72,7 +73,7 @@ try (SSLServerSocket ssocket = (SSLServerSocket) factory.createServerSocket()) { ssocket.setReuseAddress(false); - ssocket.bind(new InetSocketAddress(RANDOM_PORT)); + ssocket.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), RANDOM_PORT)); // start server Thread server = new Thread(() -> { diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/http2/server/Http2TestServer.java --- a/test/jdk/java/net/httpclient/http2/server/Http2TestServer.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/http2/server/Http2TestServer.java Thu Mar 08 17:42:16 2018 +0000 @@ -78,6 +78,11 @@ return (InetSocketAddress)server.getLocalSocketAddress(); } + public String serverAuthority() { + return InetAddress.getLoopbackAddress().getHostName() + ":" + + getAddress().getPort(); + } + public Http2TestServer(boolean secure, SSLContext context) throws Exception { this(null, secure, 0, null, context); @@ -169,7 +174,7 @@ final ServerSocket initPlaintext(int port) throws Exception { ServerSocket ss = new ServerSocket(); ss.setReuseAddress(false); - ss.bind(new InetSocketAddress(0)); + ss.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0)); return ss; } @@ -196,7 +201,7 @@ } SSLServerSocket se = (SSLServerSocket) fac.createServerSocket(); se.setReuseAddress(false); - se.bind(new InetSocketAddress(0)); + se.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0)); SSLParameters sslp = se.getSSLParameters(); sslp.setApplicationProtocols(new String[]{"h2"}); sslp.setEndpointIdentificationAlgorithm("HTTPS"); diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/http2/server/Http2TestServerConnection.java --- a/test/jdk/java/net/httpclient/http2/server/Http2TestServerConnection.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/http2/server/Http2TestServerConnection.java Thu Mar 08 17:42:16 2018 +0000 @@ -215,7 +215,7 @@ if (name == null) { // no name set. No need to check return; - } else if (name.equals("127.0.0.1")) { + } else if (name.equals("localhost")) { name = "localhost"; } final String fname = name; @@ -224,7 +224,7 @@ SNIMatcher matcher = new SNIMatcher(StandardConstants.SNI_HOST_NAME) { public boolean matches (SNIServerName n) { String host = ((SNIHostName)n).getAsciiName(); - if (host.equals("127.0.0.1")) + if (host.equals("localhost")) host = "localhost"; boolean cmp = host.equalsIgnoreCase(fname); if (cmp) diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/security/0.policy --- a/test/jdk/java/net/httpclient/security/0.policy Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/security/0.policy Thu Mar 08 17:42:16 2018 +0000 @@ -40,7 +40,7 @@ // For proxy only. Not being tested grant codebase "file:${test.classes}/proxydir/-" { permission java.net.SocketPermission "localhost:1024-", "accept,listen,connect"; - permission java.net.SocketPermission "127.0.0.1:1024-", "connect,resolve"; + permission java.net.SocketPermission "localhost:1024-", "connect,resolve"; }; diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/security/1.policy --- a/test/jdk/java/net/httpclient/security/1.policy Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/security/1.policy Thu Mar 08 17:42:16 2018 +0000 @@ -34,11 +34,11 @@ // permissions specific to this test - permission java.net.URLPermission "http://127.0.0.1:${port.number}/files/foo.txt", "GET"; + permission java.net.URLPermission "http://localhost:${port.number}/files/foo.txt", "GET"; }; // For proxy only. Not being tested grant codebase "file:${test.classes}/proxydir/-" { permission java.net.SocketPermission "localhost:1024-", "accept,listen,connect"; - permission java.net.SocketPermission "127.0.0.1:1024-", "connect,resolve"; + permission java.net.SocketPermission "localhost:1024-", "connect,resolve"; }; diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/security/10.policy --- a/test/jdk/java/net/httpclient/security/10.policy Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/security/10.policy Thu Mar 08 17:42:16 2018 +0000 @@ -33,11 +33,11 @@ permission java.lang.RuntimePermission "createClassLoader"; // permissions specific to this test - permission java.net.URLPermission "http://127.0.0.1:${port.number}/files/foo.txt", "GET:*"; + permission java.net.URLPermission "http://localhost:${port.number}/files/foo.txt", "GET:*"; }; // For proxy only. Not being tested grant codebase "file:${test.classes}/proxydir/-" { permission java.net.SocketPermission "localhost:1024-", "accept,listen,connect"; - permission java.net.SocketPermission "127.0.0.1:1024-", "connect,resolve"; + permission java.net.SocketPermission "localhost:1024-", "connect,resolve"; }; diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/security/11.policy --- a/test/jdk/java/net/httpclient/security/11.policy Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/security/11.policy Thu Mar 08 17:42:16 2018 +0000 @@ -33,13 +33,13 @@ permission java.lang.RuntimePermission "createClassLoader"; // permissions specific to this test - permission java.net.URLPermission "http://127.0.0.1:${port.number}/files/foo.txt", "GET:*"; - permission java.net.URLPermission "socket://127.0.0.1:${port.number1}", "CONNECT"; + permission java.net.URLPermission "http://localhost:${port.number}/files/foo.txt", "GET:*"; + permission java.net.URLPermission "socket://localhost:${port.number1}", "CONNECT"; }; // For proxy only. Not being tested grant codebase "file:${test.classes}/proxydir/-" { permission java.net.SocketPermission "localhost:1024-", "accept,listen,connect"; - permission java.net.SocketPermission "127.0.0.1:1024-", "connect,resolve"; + permission java.net.SocketPermission "localhost:1024-", "connect,resolve"; }; diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/security/12.policy --- a/test/jdk/java/net/httpclient/security/12.policy Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/security/12.policy Thu Mar 08 17:42:16 2018 +0000 @@ -33,13 +33,13 @@ permission java.lang.RuntimePermission "createClassLoader"; // permissions specific to this test - permission java.net.URLPermission "http://127.0.0.1:${port.number}/files/foo.txt", "GET:*"; - permission java.net.URLPermission "socket://127.0.0.1:${port.number1}", "CONNECT"; + permission java.net.URLPermission "http://localhost:${port.number}/files/foo.txt", "GET:*"; + permission java.net.URLPermission "socket://localhost:${port.number1}", "CONNECT"; }; // For proxy only. Not being tested grant codebase "file:${test.classes}/proxydir/-" { permission java.net.SocketPermission "localhost:1024-", "accept,listen,connect"; - permission java.net.SocketPermission "127.0.0.1:1024-", "connect,resolve"; + permission java.net.SocketPermission "localhost:1024-", "connect,resolve"; }; diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/security/14.policy --- a/test/jdk/java/net/httpclient/security/14.policy Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/security/14.policy Thu Mar 08 17:42:16 2018 +0000 @@ -34,11 +34,11 @@ // permissions specific to this test - permission java.net.URLPermission "http://127.0.0.1:*/files/foo.txt", "GET"; + permission java.net.URLPermission "http://localhost:*/files/foo.txt", "GET"; }; // For proxy only. Not being tested grant codebase "file:${test.classes}/proxydir/-" { permission java.net.SocketPermission "localhost:1024-", "accept,listen,connect"; - permission java.net.SocketPermission "127.0.0.1:1024-", "connect,resolve"; + permission java.net.SocketPermission "localhost:1024-", "connect,resolve"; }; diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/security/15.policy --- a/test/jdk/java/net/httpclient/security/15.policy Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/security/15.policy Thu Mar 08 17:42:16 2018 +0000 @@ -33,7 +33,7 @@ permission java.lang.RuntimePermission "createClassLoader"; // permissions specific to this test - permission java.net.URLPermission "http://127.0.0.1:*/files/foo.txt", "GET:*"; + permission java.net.URLPermission "http://localhost:*/files/foo.txt", "GET:*"; // Test checks for this explicitly permission java.lang.RuntimePermission "foobar"; @@ -43,5 +43,5 @@ // For proxy only. Not being tested grant codebase "file:${test.classes}/proxydir/-" { permission java.net.SocketPermission "localhost:1024-", "accept,listen,connect"; - permission java.net.SocketPermission "127.0.0.1:1024-", "connect,resolve"; + permission java.net.SocketPermission "localhost:1024-", "connect,resolve"; }; diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/security/2.policy --- a/test/jdk/java/net/httpclient/security/2.policy Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/security/2.policy Thu Mar 08 17:42:16 2018 +0000 @@ -34,11 +34,11 @@ // permissions specific to this test - permission java.net.URLPermission "http://127.0.0.1:*/files/*", "GET"; + permission java.net.URLPermission "http://localhost:*/files/*", "GET"; }; // For proxy only. Not being tested grant codebase "file:${test.classes}/proxydir/-" { permission java.net.SocketPermission "localhost:1024-", "accept,listen,connect"; - permission java.net.SocketPermission "127.0.0.1:1024-", "connect,resolve"; + permission java.net.SocketPermission "localhost:1024-", "connect,resolve"; }; diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/security/3.policy --- a/test/jdk/java/net/httpclient/security/3.policy Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/security/3.policy Thu Mar 08 17:42:16 2018 +0000 @@ -34,11 +34,11 @@ // permissions specific to this test - permission java.net.URLPermission "http://127.0.0.1:*/redirect/foo.txt", "GET"; + permission java.net.URLPermission "http://localhost:*/redirect/foo.txt", "GET"; }; // For proxy only. Not being tested grant codebase "file:${test.classes}/proxydir/-" { permission java.net.SocketPermission "localhost:1024-", "accept,listen,connect"; - permission java.net.SocketPermission "127.0.0.1:1024-", "connect,resolve"; + permission java.net.SocketPermission "localhost:1024-", "connect,resolve"; }; diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/security/4.policy --- a/test/jdk/java/net/httpclient/security/4.policy Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/security/4.policy Thu Mar 08 17:42:16 2018 +0000 @@ -34,12 +34,12 @@ // permissions specific to this test - permission java.net.URLPermission "http://127.0.0.1:*/redirect/foo.txt", "GET"; - permission java.net.URLPermission "http://127.0.0.1:*/redirect/bar.txt", "GET"; + permission java.net.URLPermission "http://localhost:*/redirect/foo.txt", "GET"; + permission java.net.URLPermission "http://localhost:*/redirect/bar.txt", "GET"; }; // For proxy only. Not being tested grant codebase "file:${test.classes}/proxydir/-" { permission java.net.SocketPermission "localhost:1024-", "accept,listen,connect"; - permission java.net.SocketPermission "127.0.0.1:1024-", "connect,resolve"; + permission java.net.SocketPermission "localhost:1024-", "connect,resolve"; }; diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/security/5.policy --- a/test/jdk/java/net/httpclient/security/5.policy Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/security/5.policy Thu Mar 08 17:42:16 2018 +0000 @@ -34,11 +34,11 @@ // permissions specific to this test - permission java.net.URLPermission "http://127.0.0.1:*/redirect/bar.txt", "GET"; + permission java.net.URLPermission "http://localhost:*/redirect/bar.txt", "GET"; }; // For proxy only. Not being tested grant codebase "file:${test.classes}/proxydir/-" { permission java.net.SocketPermission "localhost:1024-", "accept,listen,connect"; - permission java.net.SocketPermission "127.0.0.1:1024-", "connect,resolve"; + permission java.net.SocketPermission "localhost:1024-", "connect,resolve"; }; diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/security/6.policy --- a/test/jdk/java/net/httpclient/security/6.policy Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/security/6.policy Thu Mar 08 17:42:16 2018 +0000 @@ -34,11 +34,11 @@ // permissions specific to this test - permission java.net.URLPermission "http://127.0.0.1:*/files/foo.txt", "POST"; + permission java.net.URLPermission "http://localhost:*/files/foo.txt", "POST"; }; // For proxy only. Not being tested grant codebase "file:${test.classes}/proxydir/-" { permission java.net.SocketPermission "localhost:1024-", "accept,listen,connect"; - permission java.net.SocketPermission "127.0.0.1:1024-", "connect,resolve"; + permission java.net.SocketPermission "localhost:1024-", "connect,resolve"; }; diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/security/7.policy --- a/test/jdk/java/net/httpclient/security/7.policy Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/security/7.policy Thu Mar 08 17:42:16 2018 +0000 @@ -34,11 +34,11 @@ // permissions specific to this test - permission java.net.URLPermission "http://127.0.0.1:*/files/foo.txt", "GET:X-Bar"; + permission java.net.URLPermission "http://localhost:*/files/foo.txt", "GET:X-Bar"; }; // For proxy only. Not being tested grant codebase "file:${test.classes}/proxydir/-" { permission java.net.SocketPermission "localhost:1024-", "accept,listen,connect"; - permission java.net.SocketPermission "127.0.0.1:1024-", "connect,resolve"; + permission java.net.SocketPermission "localhost:1024-", "connect,resolve"; }; diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/security/8.policy --- a/test/jdk/java/net/httpclient/security/8.policy Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/security/8.policy Thu Mar 08 17:42:16 2018 +0000 @@ -34,11 +34,11 @@ // permissions specific to this test - permission java.net.URLPermission "http://127.0.0.1:*/files/foo.txt", "GET:X-Foo1,X-Foo,X-Bar"; + permission java.net.URLPermission "http://localhost:*/files/foo.txt", "GET:X-Foo1,X-Foo,X-Bar"; }; // For proxy only. Not being tested grant codebase "file:${test.classes}/proxydir/-" { permission java.net.SocketPermission "localhost:1024-", "accept,listen,connect"; - permission java.net.SocketPermission "127.0.0.1:1024-", "connect,resolve"; + permission java.net.SocketPermission "localhost:1024-", "connect,resolve"; }; diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/security/9.policy --- a/test/jdk/java/net/httpclient/security/9.policy Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/security/9.policy Thu Mar 08 17:42:16 2018 +0000 @@ -34,11 +34,11 @@ // permissions specific to this test - permission java.net.URLPermission "http://127.0.0.1:*/files/foo.txt", "GET:*"; + permission java.net.URLPermission "http://localhost:*/files/foo.txt", "GET:*"; }; // For proxy only. Not being tested grant codebase "file:${test.classes}/proxydir/-" { permission java.net.SocketPermission "localhost:1024-", "accept,listen,connect"; - permission java.net.SocketPermission "127.0.0.1:1024-", "connect,resolve"; + permission java.net.SocketPermission "localhost:1024-", "connect,resolve"; }; diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/security/Security.java --- a/test/jdk/java/net/httpclient/security/Security.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/security/Security.java Thu Mar 08 17:42:16 2018 +0000 @@ -61,6 +61,7 @@ import java.io.OutputStream; import java.lang.reflect.Constructor; import java.net.BindException; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.ProxySelector; import java.net.URI; @@ -179,49 +180,49 @@ tests = new TestAndResult[]{ // (0) policy does not have permission for file. Should fail test(false, () -> { // Policy 0 - URI u = URI.create("http://127.0.0.1:" + port + "/files/foo.txt"); + URI u = URI.create("http://localhost:" + port + "/files/foo.txt"); HttpRequest request = HttpRequest.newBuilder(u).GET().build(); HttpResponse response = client.send(request, ofString()); }), // (1) policy has permission for file URL test(true, () -> { //Policy 1 - URI u = URI.create("http://127.0.0.1:" + port + "/files/foo.txt"); + URI u = URI.create("http://localhost:" + port + "/files/foo.txt"); HttpRequest request = HttpRequest.newBuilder(u).GET().build(); HttpResponse response = client.send(request, ofString()); }), // (2) policy has permission for all file URLs under /files test(true, () -> { // Policy 2 - URI u = URI.create("http://127.0.0.1:" + port + "/files/foo.txt"); + URI u = URI.create("http://localhost:" + port + "/files/foo.txt"); HttpRequest request = HttpRequest.newBuilder(u).GET().build(); HttpResponse response = client.send(request, ofString()); }), // (3) policy has permission for first URL but not redirected URL test(false, () -> { // Policy 3 - URI u = URI.create("http://127.0.0.1:" + port + "/redirect/foo.txt"); + URI u = URI.create("http://localhost:" + port + "/redirect/foo.txt"); HttpRequest request = HttpRequest.newBuilder(u).GET().build(); HttpResponse response = client.send(request, ofString()); }), // (4) policy has permission for both first URL and redirected URL test(true, () -> { // Policy 4 - URI u = URI.create("http://127.0.0.1:" + port + "/redirect/foo.txt"); + URI u = URI.create("http://localhost:" + port + "/redirect/foo.txt"); HttpRequest request = HttpRequest.newBuilder(u).GET().build(); HttpResponse response = client.send(request, ofString()); }), // (5) policy has permission for redirected but not first URL test(false, () -> { // Policy 5 - URI u = URI.create("http://127.0.0.1:" + port + "/redirect/foo.txt"); + URI u = URI.create("http://localhost:" + port + "/redirect/foo.txt"); HttpRequest request = HttpRequest.newBuilder(u).GET().build(); HttpResponse response = client.send(request, ofString()); }), // (6) policy has permission for file URL, but not method test(false, () -> { //Policy 6 - URI u = URI.create("http://127.0.0.1:" + port + "/files/foo.txt"); + URI u = URI.create("http://localhost:" + port + "/files/foo.txt"); HttpRequest request = HttpRequest.newBuilder(u).GET().build(); HttpResponse response = client.send(request, ofString()); }), // (7) policy has permission for file URL, method, but not header test(false, () -> { //Policy 7 - URI u = URI.create("http://127.0.0.1:" + port + "/files/foo.txt"); + URI u = URI.create("http://localhost:" + port + "/files/foo.txt"); HttpRequest request = HttpRequest.newBuilder(u) .header("X-Foo", "bar") .GET() @@ -230,7 +231,7 @@ }), // (8) policy has permission for file URL, method and header test(true, () -> { //Policy 8 - URI u = URI.create("http://127.0.0.1:" + port + "/files/foo.txt"); + URI u = URI.create("http://localhost:" + port + "/files/foo.txt"); HttpRequest request = HttpRequest.newBuilder(u) .header("X-Foo", "bar") .GET() @@ -239,7 +240,7 @@ }), // (9) policy has permission for file URL, method and header test(true, () -> { //Policy 9 - URI u = URI.create("http://127.0.0.1:" + port + "/files/foo.txt"); + URI u = URI.create("http://localhost:" + port + "/files/foo.txt"); HttpRequest request = HttpRequest.newBuilder(u) .headers("X-Foo", "bar", "X-Bar", "foo") .GET() @@ -260,7 +261,7 @@ }), // (13) async version of test 0 test(false, () -> { // Policy 0 - URI u = URI.create("http://127.0.0.1:" + port + "/files/foo.txt"); + URI u = URI.create("http://localhost:" + port + "/files/foo.txt"); HttpRequest request = HttpRequest.newBuilder(u).GET().build(); try { HttpResponse response = client.sendAsync(request, ofString()).get(); @@ -274,7 +275,7 @@ }), // (14) async version of test 1 test(true, () -> { //Policy 1 - URI u = URI.create("http://127.0.0.1:" + port + "/files/foo.txt"); + URI u = URI.create("http://localhost:" + port + "/files/foo.txt"); HttpRequest request = HttpRequest.newBuilder(u).GET().build(); try { HttpResponse response = client.sendAsync(request, ofString()).get(); @@ -289,7 +290,7 @@ // (15) check that user provided unprivileged code running on a worker // thread does not gain ungranted privileges. test(false, () -> { //Policy 12 - URI u = URI.create("http://127.0.0.1:" + port + "/files/foo.txt"); + URI u = URI.create("http://localhost:" + port + "/files/foo.txt"); HttpRequest request = HttpRequest.newBuilder(u).GET().build(); HttpResponse.BodyHandler sth = ofString(); @@ -362,13 +363,14 @@ if (!samePort) proxyPort++; - InetSocketAddress addr = new InetSocketAddress("127.0.0.1", proxyPort); + InetSocketAddress addr = new InetSocketAddress(InetAddress.getLoopbackAddress(), + proxyPort); HttpClient cl = HttpClient.newBuilder() .proxy(ProxySelector.of(addr)) .build(); clients.add(cl); - URI u = URI.create("http://127.0.0.1:" + port + "/files/foo.txt"); + URI u = URI.create("http://localhost:" + port + "/files/foo.txt"); HttpRequest request = HttpRequest.newBuilder(u) .headers("X-Foo", "bar", "X-Bar", "foo") .build(); @@ -436,7 +438,7 @@ ch.setLevel(Level.ALL); logger.addHandler(ch); String root = System.getProperty ("test.src")+ "/docs"; - InetSocketAddress addr = new InetSocketAddress (port); + InetSocketAddress addr = new InetSocketAddress(InetAddress.getLoopbackAddress(), port); s1 = HttpServer.create (addr, 0); if (s1 instanceof HttpsServer) { throw new RuntimeException ("should not be httpsserver"); @@ -459,8 +461,8 @@ System.out.println("Port was assigned by Driver"); } System.out.println("HTTP server port = " + port); - httproot = "http://127.0.0.1:" + port + "/files/"; - redirectroot = "http://127.0.0.1:" + port + "/redirect/"; + httproot = "http://localhost:" + port + "/files/"; + redirectroot = "http://localhost:" + port + "/redirect/"; uri = new URI(httproot); fileuri = httproot + "foo.txt"; } diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/ssltest/CertificateTest.java --- a/test/jdk/java/net/httpclient/ssltest/CertificateTest.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/ssltest/CertificateTest.java Thu Mar 08 17:42:16 2018 +0000 @@ -88,7 +88,7 @@ static void test(String[] args) throws Exception { - String uri_s = "https://127.0.0.1:" + Integer.toString(port) + "/foo"; + String uri_s = "https://localhost:" + Integer.toString(port) + "/foo"; String error = null; Exception exception = null; System.out.println("Making request to " + uri_s); diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/ssltest/Server.java --- a/test/jdk/java/net/httpclient/ssltest/Server.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/ssltest/Server.java Thu Mar 08 17:42:16 2018 +0000 @@ -23,6 +23,7 @@ import com.sun.net.httpserver.*; import java.io.*; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.URI; import java.security.*; @@ -47,7 +48,8 @@ initLogger(); SSLContext ctx = getContext("TLSv1.2", certfile); Configurator cfg = new Configurator(ctx); - server = HttpsServer.create(new InetSocketAddress(0), 10); + InetSocketAddress addr = new InetSocketAddress(InetAddress.getLoopbackAddress(),0); + server = HttpsServer.create(addr, 10); server.setHttpsConfigurator(cfg); server.createContext("/", new MyHandler()); server.setExecutor((exec=Executors.newCachedThreadPool())); diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/websocket/DummyWebSocketServer.java --- a/test/jdk/java/net/httpclient/websocket/DummyWebSocketServer.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/websocket/DummyWebSocketServer.java Thu Mar 08 17:42:16 2018 +0000 @@ -24,6 +24,7 @@ import java.io.Closeable; import java.io.IOException; import java.io.UncheckedIOException; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.URI; import java.nio.ByteBuffer; @@ -167,7 +168,7 @@ ssc = ServerSocketChannel.open(); try { ssc.configureBlocking(true); - ssc.bind(new InetSocketAddress(0)); + ssc.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0)); address = (InetSocketAddress) ssc.getLocalAddress(); thread.start(); } catch (IOException e) { diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/websocket/WSHandshakeExceptionTest.java --- a/test/jdk/java/net/httpclient/websocket/WSHandshakeExceptionTest.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/websocket/WSHandshakeExceptionTest.java Thu Mar 08 17:42:16 2018 +0000 @@ -33,6 +33,8 @@ import com.sun.net.httpserver.HttpServer; import com.sun.net.httpserver.HttpsConfigurator; import com.sun.net.httpserver.HttpsServer; + +import java.net.InetAddress; import java.net.http.HttpClient; import java.net.http.WebSocket; import java.net.http.WebSocketHandshakeException; @@ -113,13 +115,13 @@ throw new AssertionError("Unexpected null sslContext"); // HTTP/1.1 - InetSocketAddress sa = new InetSocketAddress("localhost", 0); + InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0); httpTestServer = HttpServer.create(sa, 0); - httpURI = "ws://127.0.0.1:" + httpTestServer.getAddress().getPort() + "/"; + httpURI = "ws://localhost:" + httpTestServer.getAddress().getPort() + "/"; httpsTestServer = HttpsServer.create(sa, 0); httpsTestServer.setHttpsConfigurator(new HttpsConfigurator(sslContext)); - httpsURI = "wss://127.0.0.1:" + httpsTestServer.getAddress().getPort() + "/"; + httpsURI = "wss://localhost:" + httpsTestServer.getAddress().getPort() + "/"; httpTestServer.start(); httpsTestServer.start(); diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/websocket/security/WSURLPermissionTest.java --- a/test/jdk/java/net/httpclient/websocket/security/WSURLPermissionTest.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/websocket/security/WSURLPermissionTest.java Thu Mar 08 17:42:16 2018 +0000 @@ -29,6 +29,7 @@ */ import java.io.IOException; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Proxy; import java.net.ProxySelector; @@ -74,7 +75,8 @@ @BeforeTest public void setup() throws Exception { ProxyServer proxyServer = new ProxyServer(0, true); - proxyAddress = new InetSocketAddress("127.0.0.1", proxyServer.getPort()); + proxyAddress = new InetSocketAddress(InetAddress.getLoopbackAddress(), + proxyServer.getPort()); webSocketServer = new DummyWebSocketServer(); webSocketServer.open(); wsURI = webSocketServer.getURI(); diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/AuthenticationFilterTest.java --- a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/AuthenticationFilterTest.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/AuthenticationFilterTest.java Thu Mar 08 17:42:16 2018 +0000 @@ -73,14 +73,14 @@ { "http://foo.com:80", HTTP_2, null }, { "http://foo.com:80#blah", HTTP_1_1, null }, { "http://foo.com:80#blah", HTTP_2, null }, - { "http://foo.com", HTTP_1_1, "127.0.0.1:8080" }, - { "http://foo.com", HTTP_2, "127.0.0.1:8080" }, - { "http://foo.com#blah", HTTP_1_1, "127.0.0.1:8080" }, - { "http://foo.com#blah", HTTP_2, "127.0.0.1:8080" }, - { "http://foo.com:8080", HTTP_1_1, "127.0.0.1:8080" }, - { "http://foo.com:8080", HTTP_2, "127.0.0.1:8080" }, - { "http://foo.com:8080#blah", HTTP_1_1, "127.0.0.1:8080" }, - { "http://foo.com:8080#blah", HTTP_2, "127.0.0.1:8080" }, + { "http://foo.com", HTTP_1_1, "localhost:8080" }, + { "http://foo.com", HTTP_2, "localhost:8080" }, + { "http://foo.com#blah", HTTP_1_1, "localhost:8080" }, + { "http://foo.com#blah", HTTP_2, "localhost:8080" }, + { "http://foo.com:8080", HTTP_1_1, "localhost:8080" }, + { "http://foo.com:8080", HTTP_2, "localhost:8080" }, + { "http://foo.com:8080#blah", HTTP_1_1, "localhost:8080" }, + { "http://foo.com:8080#blah", HTTP_2, "localhost:8080" }, { "https://foo.com", HTTP_1_1, null }, { "https://foo.com", HTTP_2, null }, { "https://foo.com#blah", HTTP_1_1, null }, @@ -89,26 +89,26 @@ { "https://foo.com:443", HTTP_2, null }, { "https://foo.com:443#blah", HTTP_1_1, null }, { "https://foo.com:443#blah", HTTP_2, null }, - { "https://foo.com", HTTP_1_1, "127.0.0.1:8080" }, - { "https://foo.com", HTTP_2, "127.0.0.1:8080" }, - { "https://foo.com#blah", HTTP_1_1, "127.0.0.1:8080" }, - { "https://foo.com#blah", HTTP_2, "127.0.0.1:8080" }, - { "https://foo.com:8080", HTTP_1_1, "127.0.0.1:8080" }, - { "https://foo.com:8080", HTTP_2, "127.0.0.1:8080" }, - { "https://foo.com:8080#blah", HTTP_1_1, "127.0.0.1:8080" }, - { "https://foo.com:8080#blah", HTTP_2, "127.0.0.1:8080" }, + { "https://foo.com", HTTP_1_1, "localhost:8080" }, + { "https://foo.com", HTTP_2, "localhost:8080" }, + { "https://foo.com#blah", HTTP_1_1, "localhost:8080" }, + { "https://foo.com#blah", HTTP_2, "localhost:8080" }, + { "https://foo.com:8080", HTTP_1_1, "localhost:8080" }, + { "https://foo.com:8080", HTTP_2, "localhost:8080" }, + { "https://foo.com:8080#blah", HTTP_1_1, "localhost:8080" }, + { "https://foo.com:8080#blah", HTTP_2, "localhost:8080" }, { "http://foo.com:80/x/y/z", HTTP_1_1, null }, { "http://foo.com:80/x/y/z", HTTP_2, null }, { "http://foo.com:80/x/y/z#blah", HTTP_1_1, null }, { "http://foo.com:80/x/y/z#blah", HTTP_2, null }, - { "http://foo.com/x/y/z", HTTP_1_1, "127.0.0.1:8080" }, - { "http://foo.com/x/y/z", HTTP_2, "127.0.0.1:8080" }, - { "http://foo.com/x/y/z#blah", HTTP_1_1, "127.0.0.1:8080" }, - { "http://foo.com/x/y/z#blah", HTTP_2, "127.0.0.1:8080" }, - { "http://foo.com:8080/x/y/z", HTTP_1_1, "127.0.0.1:8080" }, - { "http://foo.com:8080/x/y/z", HTTP_2, "127.0.0.1:8080" }, - { "http://foo.com:8080/x/y/z#blah", HTTP_1_1, "127.0.0.1:8080" }, - { "http://foo.com:8080/x/y/z#blah", HTTP_2, "127.0.0.1:8080" }, + { "http://foo.com/x/y/z", HTTP_1_1, "localhost:8080" }, + { "http://foo.com/x/y/z", HTTP_2, "localhost:8080" }, + { "http://foo.com/x/y/z#blah", HTTP_1_1, "localhost:8080" }, + { "http://foo.com/x/y/z#blah", HTTP_2, "localhost:8080" }, + { "http://foo.com:8080/x/y/z", HTTP_1_1, "localhost:8080" }, + { "http://foo.com:8080/x/y/z", HTTP_2, "localhost:8080" }, + { "http://foo.com:8080/x/y/z#blah", HTTP_1_1, "localhost:8080" }, + { "http://foo.com:8080/x/y/z#blah", HTTP_2, "localhost:8080" }, { "https://foo.com/x/y/z", HTTP_1_1, null }, { "https://foo.com/x/y/z", HTTP_2, null }, { "https://foo.com/x/y/z#blah", HTTP_1_1, null }, @@ -117,14 +117,14 @@ { "https://foo.com:443/x/y/z", HTTP_2, null }, { "https://foo.com:443/x/y/z#blah", HTTP_1_1, null }, { "https://foo.com:443/x/y/z#blah", HTTP_2, null }, - { "https://foo.com/x/y/z", HTTP_1_1, "127.0.0.1:8080" }, - { "https://foo.com/x/y/z", HTTP_2, "127.0.0.1:8080" }, - { "https://foo.com/x/y/z#blah", HTTP_1_1, "127.0.0.1:8080" }, - { "https://foo.com/x/y/z#blah", HTTP_2, "127.0.0.1:8080" }, - { "https://foo.com:8080/x/y/z", HTTP_1_1, "127.0.0.1:8080" }, - { "https://foo.com:8080/x/y/z", HTTP_2, "127.0.0.1:8080" }, - { "https://foo.com:8080/x/y/z#blah", HTTP_1_1, "127.0.0.1:8080" }, - { "https://foo.com:8080/x/y/z#blah", HTTP_2, "127.0.0.1:8080" }, + { "https://foo.com/x/y/z", HTTP_1_1, "localhost:8080" }, + { "https://foo.com/x/y/z", HTTP_2, "localhost:8080" }, + { "https://foo.com/x/y/z#blah", HTTP_1_1, "localhost:8080" }, + { "https://foo.com/x/y/z#blah", HTTP_2, "localhost:8080" }, + { "https://foo.com:8080/x/y/z", HTTP_1_1, "localhost:8080" }, + { "https://foo.com:8080/x/y/z", HTTP_2, "localhost:8080" }, + { "https://foo.com:8080/x/y/z#blah", HTTP_1_1, "localhost:8080" }, + { "https://foo.com:8080/x/y/z#blah", HTTP_2, "localhost:8080" }, }; } diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/FlowTest.java --- a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/FlowTest.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/FlowTest.java Thu Mar 08 17:42:16 2018 +0000 @@ -29,6 +29,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Socket; import java.nio.ByteBuffer; @@ -199,14 +200,14 @@ SSLServerSocketFactory fac = ctx.getServerSocketFactory(); SSLServerSocket serv = (SSLServerSocket) fac.createServerSocket(); serv.setReuseAddress(false); - serv.bind(new InetSocketAddress(0)); + serv.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0)); SSLParameters params = serv.getSSLParameters(); params.setApplicationProtocols(new String[]{"proto2"}); serv.setSSLParameters(params); int serverPort = serv.getLocalPort(); - clientSock = new Socket("127.0.0.1", serverPort); + clientSock = new Socket("localhost", serverPort); serverSock = (SSLSocket) serv.accept(); this.buffer = new LinkedBlockingQueue<>(); this.allBytesReceived = allBytesReceived; diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/RawChannelTest.java --- a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/RawChannelTest.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/RawChannelTest.java Thu Mar 08 17:42:16 2018 +0000 @@ -27,6 +27,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.UncheckedIOException; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.ServerSocket; import java.net.Socket; @@ -83,7 +84,7 @@ public void test() throws Exception { try (ServerSocket server = new ServerSocket()) { server.setReuseAddress(false); - server.bind(new InetSocketAddress(0)); + server.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0)); int port = server.getLocalPort(); new TestServer(server).start(); @@ -188,7 +189,7 @@ } private static RawChannel channelOf(int port) throws Exception { - URI uri = URI.create("http://127.0.0.1:" + port + "/"); + URI uri = URI.create("http://localhost:" + port + "/"); print("raw channel to %s", uri.toString()); HttpRequest req = HttpRequest.newBuilder(uri).build(); // Switch on isWebSocket flag to prevent the connection from diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/SSLTubeTest.java --- a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/SSLTubeTest.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/SSLTubeTest.java Thu Mar 08 17:42:16 2018 +0000 @@ -37,6 +37,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Socket; import java.nio.ByteBuffer; @@ -86,14 +87,14 @@ SSLServerSocketFactory fac = ctx.getServerSocketFactory(); SSLServerSocket serv = (SSLServerSocket) fac.createServerSocket(); serv.setReuseAddress(false); - serv.bind(new InetSocketAddress(0)); + serv.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0)); SSLParameters params = serv.getSSLParameters(); params.setApplicationProtocols(new String[]{"proto2"}); serv.setSSLParameters(params); int serverPort = serv.getLocalPort(); - clientSock = new Socket("127.0.0.1", serverPort); + clientSock = new Socket("localhost", serverPort); serverSock = (SSLSocket) serv.accept(); this.buffer = new LinkedBlockingQueue<>(); this.allBytesReceived = allBytesReceived; diff -r c012b93297b0 -r ec34ae013fbe test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/SelectorTest.java --- a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/SelectorTest.java Thu Mar 08 17:41:52 2018 +0000 +++ b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/SelectorTest.java Thu Mar 08 17:42:16 2018 +0000 @@ -83,7 +83,7 @@ try (ServerSocket server = new ServerSocket()) { server.setReuseAddress(false); - server.bind(new InetSocketAddress(0)); + server.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0)); int port = server.getLocalPort(); out.println("Listening on port " + server.getLocalPort()); @@ -148,7 +148,7 @@ } static RawChannel getARawChannel(int port) throws Exception { - URI uri = URI.create("http://127.0.0.1:" + port + "/"); + URI uri = URI.create("http://localhost:" + port + "/"); out.println("client connecting to " + uri.toString()); HttpRequest req = HttpRequest.newBuilder(uri).build(); // Otherwise HttpClient will think this is an ordinary connection and