mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-01-17 17:21:53 +01:00
[i444] Support nonProxyHosts parameter in settings.xml
This commit is contained in:
@@ -165,6 +165,10 @@ public final class Settings {
|
||||
* The properties key for the proxy password.
|
||||
*/
|
||||
public static final String PROXY_PASSWORD = "proxy.password";
|
||||
/**
|
||||
* The properties key for the non proxy hosts.
|
||||
*/
|
||||
public static final String PROXY_NON_PROXY_HOSTS = "proxy.nonproxyhosts";
|
||||
/**
|
||||
* The properties key for the connection timeout.
|
||||
*/
|
||||
|
||||
@@ -53,13 +53,15 @@ public final class URLConnectionFactory {
|
||||
public static HttpURLConnection createHttpURLConnection(URL url) throws URLConnectionFailureException {
|
||||
HttpURLConnection conn = null;
|
||||
final String proxyUrl = Settings.getString(Settings.KEYS.PROXY_SERVER);
|
||||
|
||||
try {
|
||||
if (proxyUrl != null) {
|
||||
if (proxyUrl != null && !skipProxy(url)) {
|
||||
final int proxyPort = Settings.getInt(Settings.KEYS.PROXY_PORT);
|
||||
final SocketAddress address = new InetSocketAddress(proxyUrl, proxyPort);
|
||||
|
||||
final String username = Settings.getString(Settings.KEYS.PROXY_USERNAME);
|
||||
final String password = Settings.getString(Settings.KEYS.PROXY_PASSWORD);
|
||||
|
||||
if (username != null && password != null) {
|
||||
final Authenticator auth = new Authenticator() {
|
||||
@Override
|
||||
@@ -94,6 +96,24 @@ public final class URLConnectionFactory {
|
||||
return conn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks of for the given URL the proxy shall be used or not checking the nonProxyHosts configuration.
|
||||
* @param url The URL to check.
|
||||
* @return If the proxy shall be skip for the given URL or not.
|
||||
*/
|
||||
private static boolean skipProxy(URL url) {
|
||||
boolean skip = false;
|
||||
final String nonProxySettings = Settings.getString(Settings.KEYS.PROXY_NON_PROXY_HOSTS);
|
||||
String[] nonProxyHosts = nonProxySettings.split(",");
|
||||
for (int i = 0; i < nonProxyHosts.length; i++) {
|
||||
if (url.getHost().matches(nonProxyHosts[i])) {
|
||||
skip = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return skip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method to create an HttpURLConnection. The use of a proxy here is optional as there may be cases where a proxy is
|
||||
* configured but we don't want to use it (for example, if there's an internal repository configured)
|
||||
|
||||
Reference in New Issue
Block a user