This is an automated email from the ASF dual-hosted git repository.
bmarwell pushed a commit to branch MRESOLVER-382_outgoing_interface
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git
The following commit(s) were added to
refs/heads/MRESOLVER-382_outgoing_interface by this push:
new e4c08696 [MRESOLVER-382] implement optional bind address
e4c08696 is described below
commit e4c0869694f4728e5d08830e6304b8ee4ab72239
Author: Benjamin Marwell <[email protected]>
AuthorDate: Wed Jul 5 09:08:20 2023 +0200
[MRESOLVER-382] implement optional bind address
---
.../eclipse/aether/transport/http/HttpTransporter.java | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git
a/maven-resolver-transport-http/src/main/java/org/eclipse/aether/transport/http/HttpTransporter.java
b/maven-resolver-transport-http/src/main/java/org/eclipse/aether/transport/http/HttpTransporter.java
index e788787f..1e294611 100644
---
a/maven-resolver-transport-http/src/main/java/org/eclipse/aether/transport/http/HttpTransporter.java
+++
b/maven-resolver-transport-http/src/main/java/org/eclipse/aether/transport/http/HttpTransporter.java
@@ -24,8 +24,10 @@ import java.io.InputStream;
import java.io.InterruptedIOException;
import java.io.OutputStream;
import java.io.UncheckedIOException;
+import java.net.InetAddress;
import java.net.URI;
import java.net.URISyntaxException;
+import java.net.UnknownHostException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
@@ -33,6 +35,7 @@ import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -98,6 +101,7 @@ import static java.util.Objects.requireNonNull;
*/
final class HttpTransporter extends AbstractTransporter {
+ static final String BIND_ADDRESS = "aether.connector.bind.address";
static final String SUPPORT_WEBDAV = "aether.connector.http.supportWebDav";
static final String PREEMPTIVE_PUT_AUTH =
"aether.connector.http.preemptivePutAuth";
@@ -203,6 +207,10 @@ final class HttpTransporter extends AbstractTransporter {
this.preemptivePutAuth = // defaults to true: Wagon does same
ConfigUtils.getBoolean(
session, true, PREEMPTIVE_PUT_AUTH + "." +
repository.getId(), PREEMPTIVE_PUT_AUTH);
+ String bindAddress = ConfigUtils.getString(session, null,
BIND_ADDRESS);
+ InetAddress bindInetAddress = Optional.ofNullable(bindAddress)
+ .map(this::resolveAddressOrNull)
+ .orElse(null);
this.supportWebDav = // defaults to false: who needs it will enable it
ConfigUtils.getBoolean(session, false, SUPPORT_WEBDAV + "." +
repository.getId(), SUPPORT_WEBDAV);
String credentialEncoding = ConfigUtils.getString(
@@ -251,6 +259,7 @@ final class HttpTransporter extends AbstractTransporter {
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(connectTimeout)
.setConnectionRequestTimeout(connectTimeout)
+ .setLocalAddress(bindInetAddress)
.setSocketTimeout(requestTimeout)
.build();
@@ -295,6 +304,15 @@ final class HttpTransporter extends AbstractTransporter {
this.client = builder.build();
}
+ private InetAddress resolveAddressOrNull(String hostOrIp) {
+ try {
+ return InetAddress.getByName(hostOrIp);
+ } catch (UnknownHostException uhe) {
+ LOGGER.warn("Given bind host (" + hostOrIp + ") cannot be
resolved. Reverting to default route.");
+ return null;
+ }
+ }
+
private static HttpHost toHost(Proxy proxy) {
HttpHost host = null;
if (proxy != null) {