You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by rs...@apache.org on 2025/12/19 01:31:12 UTC
(httpcomponents-core) branch 5.4.x updated: Bind test servers to loopback address
This is an automated email from the ASF dual-hosted git repository.
rschmitt pushed a commit to branch 5.4.x
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git
The following commit(s) were added to refs/heads/5.4.x by this push:
new 73044835a Bind test servers to loopback address
73044835a is described below
commit 73044835ac60285aa4880c892073a8d1ba6d2808
Author: Ryan Schmitt <rs...@apache.org>
AuthorDate: Wed Dec 17 23:37:48 2025 -0500
Bind test servers to loopback address
Binding to 0.0.0.0 is not guaranteed to result in a socket that is
reachable via the loopback address, even when requesting an ephemeral
port assignment by binding to port 0. It is possible for another process
on the system to bind to the loopback address at that same port, and
then client requests will go to that process instead of the test server,
resulting in occasional cryptic test failures.
By instead binding to the loopback address specifically, rather than the
wildcard address, we can prevent binding to a port that is already in
use. This significantly improves the reliability of the test suite.
---
.../hc/core5/testing/classic/ClassicTestServer.java | 2 +-
.../apache/hc/core5/testing/nio/HttpTestServer.java | 3 ++-
.../hc/core5/benchmark/BenchmarkToolTest.java | 3 ++-
.../org/apache/hc/core5/testing/nio/AlpnTest.java | 11 ++++++-----
.../testing/nio/AsyncServerBootstrapFilterTest.java | 3 ++-
.../nio/ClassicToAsyncHttp1TransportTest.java | 3 ++-
.../testing/nio/ClassicToAsyncTransportTest.java | 7 ++++---
.../org/apache/hc/core5/testing/nio/H2AlpnTest.java | 3 ++-
.../apache/hc/core5/testing/nio/H2ConnPoolTest.java | 3 ++-
.../nio/H2CoreTransportMultiplexingTest.java | 11 ++++++-----
.../testing/nio/H2ServerBootstrapFiltersTest.java | 3 ++-
.../core5/testing/nio/Http1AuthenticationTest.java | 7 ++++---
.../core5/testing/nio/Http1CoreTransportTest.java | 3 ++-
.../hc/core5/testing/nio/HttpCoreTransportTest.java | 13 +++++++------
.../hc/core5/testing/nio/TLSIntegrationTest.java | 6 +++---
.../apache/hc/core5/testing/nio/TLSUpgradeTest.java | 3 ++-
.../testing/nio/TestDefaultListeningIOReactor.java | 7 ++++---
.../core5/testing/reactive/ReactiveClientTest.java | 3 ++-
.../apache/hc/core5/ssl/TestSSLContextBuilder.java | 21 +++++++++++----------
19 files changed, 66 insertions(+), 49 deletions(-)
diff --git a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/ClassicTestServer.java b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/ClassicTestServer.java
index 01f624292..46fb945ec 100644
--- a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/ClassicTestServer.java
+++ b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/ClassicTestServer.java
@@ -191,7 +191,7 @@ public void start() throws IOException {
final HttpServer server = new HttpServer(
0,
httpService,
- null,
+ InetAddress.getLoopbackAddress(),
socketConfig,
null,
new LoggingBHttpServerConnectionFactory(
diff --git a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/HttpTestServer.java b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/HttpTestServer.java
index ec127406c..7218aaab7 100644
--- a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/HttpTestServer.java
+++ b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/HttpTestServer.java
@@ -28,6 +28,7 @@
package org.apache.hc.core5.testing.nio;
import java.io.IOException;
+import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.List;
@@ -112,7 +113,7 @@ public void configure(final Decorator<AsyncServerExchangeHandler> exchangeHandle
public InetSocketAddress startExecution(final IOEventHandlerFactory handlerFactory) throws Exception {
execute(handlerFactory);
- final Future<ListenerEndpoint> future = listen(new InetSocketAddress(0));
+ final Future<ListenerEndpoint> future = listen(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
final ListenerEndpoint listener = future.get();
return (InetSocketAddress) listener.getAddress();
}
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/benchmark/BenchmarkToolTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/benchmark/BenchmarkToolTest.java
index f21d948f6..719b3ef5b 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/benchmark/BenchmarkToolTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/benchmark/BenchmarkToolTest.java
@@ -27,6 +27,7 @@
package org.apache.hc.core5.benchmark;
import java.io.IOException;
+import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.concurrent.Future;
import java.util.stream.Stream;
@@ -105,7 +106,7 @@ public void handle(
.setVersionPolicy(versionPolicy)
.create();
server.start();
- final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0), URIScheme.HTTP);
+ final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), URIScheme.HTTP);
final ListenerEndpoint listener = future.get();
address = (InetSocketAddress) listener.getAddress();
}
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/AlpnTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/AlpnTest.java
index 82d13466d..9b26e8509 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/AlpnTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/AlpnTest.java
@@ -29,6 +29,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
+import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.concurrent.Future;
import java.util.function.Function;
@@ -128,7 +129,7 @@ void setup() throws Exception {
@Test
void testForceHttp1() throws Exception {
final HttpAsyncServer server = serverResource.start();
- final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0), URIScheme.HTTPS);
+ final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), URIScheme.HTTPS);
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
final HttpAsyncRequester requester = clientResource.start();
@@ -153,7 +154,7 @@ void testForceHttp1GlobalPolicy() throws Exception {
serverResource.configure(bootstrap ->
bootstrap.setVersionPolicy(HttpVersionPolicy.FORCE_HTTP_1));
final HttpAsyncServer server = serverResource.start();
- final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0), URIScheme.HTTPS);
+ final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), URIScheme.HTTPS);
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
final HttpAsyncRequester requester = clientResource.start();
@@ -176,7 +177,7 @@ void testForceHttp1GlobalPolicy() throws Exception {
@Test
void testForceHttp2() throws Exception {
final HttpAsyncServer server = serverResource.start();
- final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0), URIScheme.HTTPS);
+ final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), URIScheme.HTTPS);
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
final HttpAsyncRequester requester = clientResource.start();
@@ -201,7 +202,7 @@ void testForceHttp2GlobalPolicy() throws Exception {
serverResource.configure(bootstrap ->
bootstrap.setVersionPolicy(HttpVersionPolicy.FORCE_HTTP_2));
final HttpAsyncServer server = serverResource.start();
- final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0), URIScheme.HTTPS);
+ final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), URIScheme.HTTPS);
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
final HttpAsyncRequester requester = clientResource.start();
@@ -224,7 +225,7 @@ void testForceHttp2GlobalPolicy() throws Exception {
@Test
void testNegotiateProtocol() throws Exception {
final HttpAsyncServer server = serverResource.start();
- final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0), URIScheme.HTTPS);
+ final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), URIScheme.HTTPS);
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
final HttpAsyncRequester requester = clientResource.start();
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/AsyncServerBootstrapFilterTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/AsyncServerBootstrapFilterTest.java
index 6707b2397..e9aa29961 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/AsyncServerBootstrapFilterTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/AsyncServerBootstrapFilterTest.java
@@ -30,6 +30,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import java.io.IOException;
+import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.concurrent.Future;
@@ -125,7 +126,7 @@ public void pushPromise(
@Test
void testFilters() throws Exception {
final HttpAsyncServer server = serverResource.start();
- final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0), URIScheme.HTTP);
+ final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), URIScheme.HTTP);
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
final HttpAsyncRequester requester = clientResource.start();
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/ClassicToAsyncHttp1TransportTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/ClassicToAsyncHttp1TransportTest.java
index 3842b1e72..5e312e44c 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/ClassicToAsyncHttp1TransportTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/ClassicToAsyncHttp1TransportTest.java
@@ -27,6 +27,7 @@
package org.apache.hc.core5.testing.nio;
+import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.Random;
import java.util.concurrent.Future;
@@ -62,7 +63,7 @@ void test_request_handling_no_keep_alive(final int contentSize) throws Exception
final HttpAsyncServer server = serverResource.start();
registerHandler("/echo", () -> new EchoHandler(1024));
- final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0), scheme);
+ final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), scheme);
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
final HttpAsyncRequester requester = clientResource.start();
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/ClassicToAsyncTransportTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/ClassicToAsyncTransportTest.java
index e9c82c0c8..022cd62cb 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/ClassicToAsyncTransportTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/ClassicToAsyncTransportTest.java
@@ -32,6 +32,7 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
+import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
@@ -151,7 +152,7 @@ void test_request_execution() throws Exception {
final HttpAsyncServer server = serverResource.start();
registerHandler("/echo", () -> new EchoHandler(1024));
- final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0), scheme);
+ final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), scheme);
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
final HttpAsyncRequester requester = clientResource.start();
@@ -228,7 +229,7 @@ void test_request_handling(final String method) throws Exception {
});
final HttpAsyncServer server = serverResource.start();
- final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0), scheme);
+ final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), scheme);
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
final HttpAsyncRequester requester = clientResource.start();
@@ -324,7 +325,7 @@ void test_request_handling_full_streaming() throws Exception {
});
final HttpAsyncServer server = serverResource.start();
- final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0), scheme);
+ final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), scheme);
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
final HttpAsyncRequester requester = clientResource.start();
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2AlpnTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2AlpnTest.java
index 39c39b551..db4726ecc 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2AlpnTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2AlpnTest.java
@@ -32,6 +32,7 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
@@ -114,7 +115,7 @@ public H2AlpnTest(final boolean strictALPN, final boolean h2Allowed) throws Exce
@Test
void testALPN() throws Exception {
final HttpAsyncServer server = serverResource.start();
- final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0), URIScheme.HTTPS);
+ final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), URIScheme.HTTPS);
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
final H2MultiplexingRequester requester = clientResource.start();
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2ConnPoolTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2ConnPoolTest.java
index e72e4b1f3..7c3a4c514 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2ConnPoolTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2ConnPoolTest.java
@@ -27,6 +27,7 @@
package org.apache.hc.core5.testing.nio;
+import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicLong;
@@ -112,7 +113,7 @@ void testManyGetSession() throws Exception {
final int n = 200;
final HttpAsyncServer server = serverResource.start();
- final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0), URIScheme.HTTP);
+ final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), URIScheme.HTTP);
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
final HttpHost target = new HttpHost(URIScheme.HTTP.id, "localhost", address.getPort());
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2CoreTransportMultiplexingTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2CoreTransportMultiplexingTest.java
index 408ff8d7e..6d742dce4 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2CoreTransportMultiplexingTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2CoreTransportMultiplexingTest.java
@@ -29,6 +29,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
+import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.LinkedList;
import java.util.Queue;
@@ -109,7 +110,7 @@ public H2CoreTransportMultiplexingTest(final URIScheme scheme) {
@Test
void testSequentialRequests() throws Exception {
final HttpAsyncServer server = serverResource.start();
- final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0), scheme);
+ final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), scheme);
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
final H2MultiplexingRequester requester = clientResource.start();
@@ -152,7 +153,7 @@ void testSequentialRequests() throws Exception {
@Test
void testLargeRequest() throws Exception {
final HttpAsyncServer server = serverResource.start();
- final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0), scheme);
+ final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), scheme);
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
final H2MultiplexingRequester requester = clientResource.start();
@@ -173,7 +174,7 @@ void testLargeRequest() throws Exception {
@Test
void testMultiplexedRequests() throws Exception {
final HttpAsyncServer server = serverResource.start();
- final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0), scheme);
+ final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), scheme);
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
final H2MultiplexingRequester requester = clientResource.start();
@@ -208,7 +209,7 @@ void testMultiplexedRequests() throws Exception {
@Test
void testValidityCheck() throws Exception {
final HttpAsyncServer server = serverResource.start();
- final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0), scheme);
+ final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), scheme);
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
final H2MultiplexingRequester requester = clientResource.start();
@@ -256,7 +257,7 @@ void testValidityCheck() throws Exception {
@Test
void testMultiplexedRequestCancellation() throws Exception {
final HttpAsyncServer server = serverResource.start();
- final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0), scheme);
+ final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), scheme);
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
final H2MultiplexingRequester requester = clientResource.start();
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2ServerBootstrapFiltersTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2ServerBootstrapFiltersTest.java
index 61d2a8522..5c6d69970 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2ServerBootstrapFiltersTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/H2ServerBootstrapFiltersTest.java
@@ -30,6 +30,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import java.io.IOException;
+import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.concurrent.Future;
@@ -129,7 +130,7 @@ public void pushPromise(
void testSequentialRequests() throws Exception {
final HttpAsyncServer server = serverResource.start();
- final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0), URIScheme.HTTP);
+ final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), URIScheme.HTTP);
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
final HttpAsyncRequester requester = clientResource.start();
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1AuthenticationTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1AuthenticationTest.java
index 3a77f018e..9b0fe3854 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1AuthenticationTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1AuthenticationTest.java
@@ -29,6 +29,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
+import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
import java.util.Random;
@@ -137,7 +138,7 @@ protected AsyncEntityProducer generateResponseContent(final HttpResponse unautho
@Test
void testGetRequestAuthentication() throws Exception {
final HttpAsyncServer server = serverResource.start();
- final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0), URIScheme.HTTP);
+ final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), URIScheme.HTTP);
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
final HttpAsyncRequester requester = clientResource.start();
@@ -171,7 +172,7 @@ void testGetRequestAuthentication() throws Exception {
@Test
void testPostRequestAuthentication() throws Exception {
final HttpAsyncServer server = serverResource.start();
- final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0), URIScheme.HTTP);
+ final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), URIScheme.HTTP);
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
final HttpAsyncRequester requester = clientResource.start();
@@ -209,7 +210,7 @@ void testPostRequestAuthentication() throws Exception {
@Test
void testPostRequestAuthenticationNoExpectContinue() throws Exception {
final HttpAsyncServer server = serverResource.start();
- final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0), URIScheme.HTTP);
+ final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), URIScheme.HTTP);
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
final HttpAsyncRequester requester = clientResource.start();
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1CoreTransportTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1CoreTransportTest.java
index e309d3bdd..ebf0e1636 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1CoreTransportTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1CoreTransportTest.java
@@ -30,6 +30,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import java.io.IOException;
+import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.concurrent.Future;
@@ -147,7 +148,7 @@ HttpAsyncRequester clientStart() {
@Test
void testSequentialRequestsNonPersistentConnection() throws Exception {
final HttpAsyncServer server = serverResource.start();
- final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0), scheme);
+ final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), scheme);
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
final HttpAsyncRequester requester = clientResource.start();
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/HttpCoreTransportTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/HttpCoreTransportTest.java
index a9049b2e9..a5ccd65ba 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/HttpCoreTransportTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/HttpCoreTransportTest.java
@@ -30,6 +30,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import java.io.IOException;
+import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.LinkedList;
import java.util.Queue;
@@ -76,7 +77,7 @@ public HttpCoreTransportTest(final URIScheme scheme) {
@Test
void testSequentialRequests() throws Exception {
final HttpAsyncServer server = serverStart();
- final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0), scheme);
+ final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), scheme);
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
final HttpAsyncRequester requester = clientStart();
@@ -119,7 +120,7 @@ void testSequentialRequests() throws Exception {
@Test
void testLargeRequest() throws Exception {
final HttpAsyncServer server = serverStart();
- final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0), scheme);
+ final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), scheme);
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
final HttpAsyncRequester requester = clientStart();
@@ -140,7 +141,7 @@ void testLargeRequest() throws Exception {
@Test
void testSequentialRequestsNonPersistentConnection() throws Exception {
final HttpAsyncServer server = serverStart();
- final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0), scheme);
+ final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), scheme);
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
final HttpAsyncRequester requester = clientStart();
@@ -183,7 +184,7 @@ void testSequentialRequestsNonPersistentConnection() throws Exception {
@Test
void testSequentialRequestsSameEndpoint() throws Exception {
final HttpAsyncServer server = serverStart();
- final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0), scheme);
+ final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), scheme);
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
final HttpAsyncRequester requester = clientStart();
@@ -234,7 +235,7 @@ void testSequentialRequestsSameEndpoint() throws Exception {
@Test
void testPipelinedRequests() throws Exception {
final HttpAsyncServer server = serverStart();
- final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0), scheme);
+ final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), scheme);
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
final HttpAsyncRequester requester = clientStart();
@@ -277,7 +278,7 @@ void testPipelinedRequests() throws Exception {
@Test
void testNonPersistentHeads() throws Exception {
final HttpAsyncServer server = serverStart();
- final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0), scheme);
+ final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), scheme);
final ListenerEndpoint listener = future.get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
final HttpAsyncRequester requester = clientStart();
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TLSIntegrationTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TLSIntegrationTest.java
index 879eb2309..8ea51341d 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TLSIntegrationTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TLSIntegrationTest.java
@@ -172,7 +172,7 @@ HttpAsyncRequester createClient(final TlsStrategy tlsStrategy) {
}
Future<TlsDetails> executeTlsHandshake() throws Exception {
- final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0), URIScheme.HTTPS);
+ final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), URIScheme.HTTPS);
final ListenerEndpoint listener = future.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
@@ -257,7 +257,7 @@ void testTLSClientAuthFailure() throws Exception {
client = createClient(clientTlsStrategy);
client.start();
- final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0), URIScheme.HTTPS);
+ final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), URIScheme.HTTPS);
final ListenerEndpoint listener = future.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
@@ -367,7 +367,7 @@ void testHostNameVerification() throws Exception {
client = createClient(new BasicClientTlsStrategy(SSLTestContexts.createClientSSLContext()));
client.start();
- final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0), URIScheme.HTTPS);
+ final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), URIScheme.HTTPS);
final ListenerEndpoint listener = future.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TLSUpgradeTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TLSUpgradeTest.java
index 025f04b1f..8809683b5 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TLSUpgradeTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TLSUpgradeTest.java
@@ -29,6 +29,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
+import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.concurrent.Future;
@@ -101,7 +102,7 @@ public TLSUpgradeTest() {
@Test
void testTLSUpgrade() throws Exception {
final HttpAsyncServer server = serverResource.start();
- final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(0), URIScheme.HTTPS);
+ final Future<ListenerEndpoint> future = server.listen(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), URIScheme.HTTPS);
final ListenerEndpoint listener = future.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
final HttpAsyncRequester requester = clientResource.start();
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TestDefaultListeningIOReactor.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TestDefaultListeningIOReactor.java
index d183d391b..3ccd7218a 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TestDefaultListeningIOReactor.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TestDefaultListeningIOReactor.java
@@ -27,6 +27,7 @@
package org.apache.hc.core5.testing.nio;
+import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.Set;
import java.util.concurrent.ExecutionException;
@@ -73,10 +74,10 @@ void testEndpointUpAndDown() throws Exception {
Assertions.assertNotNull(endpoints);
Assertions.assertEquals(0, endpoints.size());
- final Future<ListenerEndpoint> future1 = ioReactor.listen(new InetSocketAddress(0));
+ final Future<ListenerEndpoint> future1 = ioReactor.listen(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
final ListenerEndpoint endpoint1 = future1.get();
- final Future<ListenerEndpoint> future2 = ioReactor.listen(new InetSocketAddress(0));
+ final Future<ListenerEndpoint> future2 = ioReactor.listen(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
final ListenerEndpoint endpoint2 = future2.get();
final int port = ((InetSocketAddress) endpoint2.getAddress()).getPort();
@@ -103,7 +104,7 @@ void testEndpointUpAndDown() throws Exception {
void testEndpointAlreadyBound() throws Exception {
ioReactor.start();
- final Future<ListenerEndpoint> future1 = ioReactor.listen(new InetSocketAddress(0));
+ final Future<ListenerEndpoint> future1 = ioReactor.listen(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
final ListenerEndpoint endpoint1 = future1.get();
final int port = ((InetSocketAddress) endpoint1.getAddress()).getPort();
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/reactive/ReactiveClientTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/reactive/ReactiveClientTest.java
index d83d1db6b..dc946779b 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/reactive/ReactiveClientTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/reactive/ReactiveClientTest.java
@@ -31,6 +31,7 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketTimeoutException;
import java.net.URI;
@@ -279,7 +280,7 @@ void testResponseCancellation() throws Exception {
private InetSocketAddress startServer() throws IOException, InterruptedException, ExecutionException {
final HttpAsyncServer server = serverResource.start();
- final ListenerEndpoint listener = server.listen(new InetSocketAddress(0), URIScheme.HTTP).get();
+ final ListenerEndpoint listener = server.listen(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), URIScheme.HTTP).get();
final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
return address;
}
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/ssl/TestSSLContextBuilder.java b/httpcore5/src/test/java/org/apache/hc/core5/ssl/TestSSLContextBuilder.java
index 6da19a1d1..81ac48c28 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/ssl/TestSSLContextBuilder.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/ssl/TestSSLContextBuilder.java
@@ -30,6 +30,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
@@ -318,7 +319,7 @@ void testSSLHandshakeServerTrusted() throws Exception {
.build();
Assertions.assertNotNull(clientSslContext);
final ServerSocket serverSocket = serverSslContext.getServerSocketFactory().createServerSocket();
- serverSocket.bind(new InetSocketAddress(0));
+ serverSocket.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
this.executorService = Executors.newSingleThreadExecutor();
final Future<Boolean> future = this.executorService.submit(() -> {
@@ -359,7 +360,7 @@ void testSSLHandshakeServerNotTrusted() throws Exception {
.build();
Assertions.assertNotNull(clientSslContext);
final ServerSocket serverSocket = serverSslContext.getServerSocketFactory().createServerSocket();
- serverSocket.bind(new InetSocketAddress(0));
+ serverSocket.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
this.executorService = Executors.newSingleThreadExecutor();
this.executorService.submit(() -> {
@@ -399,7 +400,7 @@ void testSSLHandshakeServerCustomTrustStrategy() throws Exception {
Assertions.assertNotNull(clientSslContext);
final ServerSocket serverSocket = serverSslContext.getServerSocketFactory().createServerSocket();
- serverSocket.bind(new InetSocketAddress(0));
+ serverSocket.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
this.executorService = Executors.newSingleThreadExecutor();
final Future<Boolean> future = this.executorService.submit(() -> {
@@ -459,7 +460,7 @@ void testSSLHandshakeClientUnauthenticated() throws Exception {
Assertions.assertNotNull(clientSslContext);
final SSLServerSocket serverSocket = (SSLServerSocket) serverSslContext.getServerSocketFactory().createServerSocket();
serverSocket.setWantClientAuth(true);
- serverSocket.bind(new InetSocketAddress(0));
+ serverSocket.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
this.executorService = Executors.newSingleThreadExecutor();
final Future<Principal> future = this.executorService.submit(() -> {
@@ -508,7 +509,7 @@ void testSSLHandshakeClientUnauthenticatedError() throws Exception {
Assertions.assertNotNull(clientSslContext);
final SSLServerSocket serverSocket = (SSLServerSocket) serverSslContext.getServerSocketFactory().createServerSocket();
serverSocket.setNeedClientAuth(true);
- serverSocket.bind(new InetSocketAddress(0));
+ serverSocket.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
this.executorService = Executors.newSingleThreadExecutor();
this.executorService.submit(() -> {
@@ -548,7 +549,7 @@ void testSSLHandshakeClientAuthenticated() throws Exception {
Assertions.assertNotNull(clientSslContext);
final SSLServerSocket serverSocket = (SSLServerSocket) serverSslContext.getServerSocketFactory().createServerSocket();
serverSocket.setNeedClientAuth(true);
- serverSocket.bind(new InetSocketAddress(0));
+ serverSocket.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
this.executorService = Executors.newSingleThreadExecutor();
final Future<Principal> future = this.executorService.submit(() -> {
@@ -597,7 +598,7 @@ void testSSLHandshakeClientAuthenticatedPrivateKeyStrategy() throws Exception {
Assertions.assertNotNull(clientSslContext);
final SSLServerSocket serverSocket = (SSLServerSocket) serverSslContext.getServerSocketFactory().createServerSocket();
serverSocket.setNeedClientAuth(true);
- serverSocket.bind(new InetSocketAddress(0));
+ serverSocket.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
this.executorService = Executors.newSingleThreadExecutor();
final Future<Principal> future = this.executorService.submit(() -> {
@@ -645,7 +646,7 @@ void testSSLHandshakeProtocolMismatch1() throws Exception {
final Set<String> supportedServerProtocols = new LinkedHashSet<>(Arrays.asList(serverSocket.getSupportedProtocols()));
Assertions.assertTrue(supportedServerProtocols.contains("TLSv1"));
serverSocket.setEnabledProtocols(new String[] {"TLSv1"});
- serverSocket.bind(new InetSocketAddress(0));
+ serverSocket.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
this.executorService = Executors.newSingleThreadExecutor();
this.executorService.submit(() -> {
@@ -688,7 +689,7 @@ void testSSLHandshakeProtocolMismatch2() throws Exception {
final Set<String> supportedServerProtocols = new LinkedHashSet<>(Arrays.asList(serverSocket.getSupportedProtocols()));
Assertions.assertTrue(supportedServerProtocols.contains("SSLv3"));
serverSocket.setEnabledProtocols(new String[] {"SSLv3"});
- serverSocket.bind(new InetSocketAddress(0));
+ serverSocket.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
this.executorService = Executors.newSingleThreadExecutor();
this.executorService.submit(() -> {
@@ -729,7 +730,7 @@ void testJSSEEndpointIdentification() throws Exception {
.build();
Assertions.assertNotNull(clientSslContext);
final SSLServerSocket serverSocket = (SSLServerSocket) serverSslContext.getServerSocketFactory().createServerSocket();
- serverSocket.bind(new InetSocketAddress(0));
+ serverSocket.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
this.executorService = Executors.newSingleThreadExecutor();
this.executorService.submit(() -> {