mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-08 14:35:45 +01:00
use proxies util class to determine if proxy settings should be used
This commit is contained in:
@@ -127,7 +127,7 @@ public class URLHttpClient implements HttpClient
|
|||||||
*/
|
*/
|
||||||
@Inject
|
@Inject
|
||||||
public URLHttpClient(SCMContextProvider context,
|
public URLHttpClient(SCMContextProvider context,
|
||||||
ScmConfiguration configuration)
|
ScmConfiguration configuration)
|
||||||
{
|
{
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
@@ -169,7 +169,7 @@ public class URLHttpClient implements HttpClient
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public HttpResponse post(String url, Map<String, List<String>> parameters)
|
public HttpResponse post(String url, Map<String, List<String>> parameters)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
HttpURLConnection connection = (HttpURLConnection) openConnection(null,
|
HttpURLConnection connection = (HttpURLConnection) openConnection(null,
|
||||||
url);
|
url);
|
||||||
@@ -233,7 +233,7 @@ public class URLHttpClient implements HttpClient
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public HttpResponse get(String url, Map<String, List<String>> parameters)
|
public HttpResponse get(String url, Map<String, List<String>> parameters)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
url = createGetUrl(url, parameters);
|
url = createGetUrl(url, parameters);
|
||||||
|
|
||||||
@@ -256,7 +256,7 @@ public class URLHttpClient implements HttpClient
|
|||||||
String url = createGetUrl(request.getUrl(), request.getParameters());
|
String url = createGetUrl(request.getUrl(), request.getParameters());
|
||||||
|
|
||||||
return new URLHttpResponse(openConnection(request, url),
|
return new URLHttpResponse(openConnection(request, url),
|
||||||
request.isDecodeGZip());
|
request.isDecodeGZip());
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
@@ -271,8 +271,7 @@ public class URLHttpClient implements HttpClient
|
|||||||
* @param password
|
* @param password
|
||||||
*/
|
*/
|
||||||
private void appendBasicAuthHeader(HttpURLConnection connection,
|
private void appendBasicAuthHeader(HttpURLConnection connection,
|
||||||
String header, String username,
|
String header, String username, String password)
|
||||||
String password)
|
|
||||||
{
|
{
|
||||||
if (Util.isNotEmpty(username) || Util.isNotEmpty(password))
|
if (Util.isNotEmpty(username) || Util.isNotEmpty(password))
|
||||||
{
|
{
|
||||||
@@ -288,7 +287,7 @@ public class URLHttpClient implements HttpClient
|
|||||||
|
|
||||||
auth = new String(Base64.encode(auth.getBytes()));
|
auth = new String(Base64.encode(auth.getBytes()));
|
||||||
connection.addRequestProperty(header,
|
connection.addRequestProperty(header,
|
||||||
PREFIX_BASIC_AUTHENTICATION.concat(auth));
|
PREFIX_BASIC_AUTHENTICATION.concat(auth));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -300,7 +299,7 @@ public class URLHttpClient implements HttpClient
|
|||||||
* @param connection
|
* @param connection
|
||||||
*/
|
*/
|
||||||
private void appendHeaders(Map<String, List<String>> headers,
|
private void appendHeaders(Map<String, List<String>> headers,
|
||||||
URLConnection connection)
|
URLConnection connection)
|
||||||
{
|
{
|
||||||
if (Util.isNotEmpty(headers))
|
if (Util.isNotEmpty(headers))
|
||||||
{
|
{
|
||||||
@@ -343,8 +342,8 @@ public class URLHttpClient implements HttpClient
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
private void appendPostParameter(HttpURLConnection connection,
|
private void appendPostParameter(HttpURLConnection connection,
|
||||||
Map<String, List<String>> parameters)
|
Map<String, List<String>> parameters)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
if (Util.isNotEmpty(parameters))
|
if (Util.isNotEmpty(parameters))
|
||||||
{
|
{
|
||||||
@@ -395,7 +394,7 @@ public class URLHttpClient implements HttpClient
|
|||||||
* @param connection
|
* @param connection
|
||||||
*/
|
*/
|
||||||
private void applySSLSettings(HttpRequest request,
|
private void applySSLSettings(HttpRequest request,
|
||||||
HttpsURLConnection connection)
|
HttpsURLConnection connection)
|
||||||
{
|
{
|
||||||
if (request.isDisableCertificateValidation())
|
if (request.isDisableCertificateValidation())
|
||||||
{
|
{
|
||||||
@@ -511,7 +510,7 @@ public class URLHttpClient implements HttpClient
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
private HttpURLConnection openConnection(HttpRequest request, String spec)
|
private HttpURLConnection openConnection(HttpRequest request, String spec)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
return openConnection(request, new URL(spec));
|
return openConnection(request, new URL(spec));
|
||||||
}
|
}
|
||||||
@@ -529,29 +528,30 @@ public class URLHttpClient implements HttpClient
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
private HttpURLConnection openConnection(HttpRequest request, URL url)
|
private HttpURLConnection openConnection(HttpRequest request, URL url)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
if (request == null)
|
if (request == null)
|
||||||
{
|
{
|
||||||
|
|
||||||
// TODO improve
|
// TODO improve
|
||||||
request = new HttpRequest(url.toExternalForm());
|
request = new HttpRequest(url.toExternalForm());
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpURLConnection connection = null;
|
HttpURLConnection connection = null;
|
||||||
|
|
||||||
if (!request.isIgnoreProxySettings() && configuration.isEnableProxy())
|
if (!request.isIgnoreProxySettings()
|
||||||
|
&& Proxies.isEnabled(configuration, url))
|
||||||
{
|
{
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
{
|
{
|
||||||
logger.debug("fetch '{}' using proxy {}:{}",
|
logger.debug("fetch '{}' using proxy {}:{}",
|
||||||
new Object[] { url.toExternalForm(),
|
new Object[] { url.toExternalForm(),
|
||||||
configuration.getProxyServer(),
|
configuration.getProxyServer(), configuration.getProxyPort() });
|
||||||
configuration.getProxyPort() });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SocketAddress address =
|
SocketAddress address =
|
||||||
new InetSocketAddress(configuration.getProxyServer(),
|
new InetSocketAddress(configuration.getProxyServer(),
|
||||||
configuration.getProxyPort());
|
configuration.getProxyPort());
|
||||||
|
|
||||||
connection =
|
connection =
|
||||||
(HttpURLConnection) url.openConnection(new Proxy(Proxy.Type.HTTP,
|
(HttpURLConnection) url.openConnection(new Proxy(Proxy.Type.HTTP,
|
||||||
@@ -590,19 +590,19 @@ public class URLHttpClient implements HttpClient
|
|||||||
String password = request.getPassword();
|
String password = request.getPassword();
|
||||||
|
|
||||||
appendBasicAuthHeader(connection, HEADER_AUTHORIZATION, username,
|
appendBasicAuthHeader(connection, HEADER_AUTHORIZATION, username,
|
||||||
password);
|
password);
|
||||||
}
|
}
|
||||||
|
|
||||||
connection.setRequestProperty(HEADER_ACCEPT_ENCODING,
|
connection.setRequestProperty(HEADER_ACCEPT_ENCODING,
|
||||||
HEADER_ACCEPT_ENCODING_VALUE);
|
HEADER_ACCEPT_ENCODING_VALUE);
|
||||||
connection.setRequestProperty(
|
connection.setRequestProperty(HEADER_USERAGENT,
|
||||||
HEADER_USERAGENT, HEADER_USERAGENT_VALUE.concat(context.getVersion()));
|
HEADER_USERAGENT_VALUE.concat(context.getVersion()));
|
||||||
|
|
||||||
String username = configuration.getProxyUser();
|
String username = configuration.getProxyUser();
|
||||||
String password = configuration.getProxyPassword();
|
String password = configuration.getProxyPassword();
|
||||||
|
|
||||||
appendBasicAuthHeader(connection, HEADER_PROXY_AUTHORIZATION, username,
|
appendBasicAuthHeader(connection, HEADER_PROXY_AUTHORIZATION, username,
|
||||||
password);
|
password);
|
||||||
|
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ import java.util.Set;
|
|||||||
import javax.xml.bind.JAXBContext;
|
import javax.xml.bind.JAXBContext;
|
||||||
import javax.xml.bind.JAXBException;
|
import javax.xml.bind.JAXBException;
|
||||||
import javax.xml.bind.Marshaller;
|
import javax.xml.bind.Marshaller;
|
||||||
|
import sonia.scm.net.Proxies;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -215,7 +216,7 @@ public class AetherPluginHandler
|
|||||||
RemoteRepository rr = new RemoteRepository(repository.getId(), "default",
|
RemoteRepository rr = new RemoteRepository(repository.getId(), "default",
|
||||||
repository.getUrl());
|
repository.getUrl());
|
||||||
|
|
||||||
if (configuration.isEnableProxy())
|
if (Proxies.isEnabled(configuration, rr.getHost()))
|
||||||
{
|
{
|
||||||
Proxy proxy = DefaultProxySelector.createProxy(configuration);
|
Proxy proxy = DefaultProxySelector.createProxy(configuration);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user