Commits

Sebastian Sdorra committed 07a951f

use proxies util class to determine if proxy settings should be used

Comments (0)

Files changed (2)

scm-webapp/src/main/java/sonia/scm/net/URLHttpClient.java

    */
   @Inject
   public URLHttpClient(SCMContextProvider context,
-                       ScmConfiguration configuration)
+    ScmConfiguration configuration)
   {
     this.context = context;
     this.configuration = configuration;
    */
   @Override
   public HttpResponse post(String url, Map<String, List<String>> parameters)
-          throws IOException
+    throws IOException
   {
     HttpURLConnection connection = (HttpURLConnection) openConnection(null,
                                      url);
    */
   @Override
   public HttpResponse get(String url, Map<String, List<String>> parameters)
-          throws IOException
+    throws IOException
   {
     url = createGetUrl(url, parameters);
 
     String url = createGetUrl(request.getUrl(), request.getParameters());
 
     return new URLHttpResponse(openConnection(request, url),
-                               request.isDecodeGZip());
+      request.isDecodeGZip());
   }
 
   //~--- methods --------------------------------------------------------------
    * @param password
    */
   private void appendBasicAuthHeader(HttpURLConnection connection,
-                                     String header, String username,
-                                     String password)
+    String header, String username, String password)
   {
     if (Util.isNotEmpty(username) || Util.isNotEmpty(password))
     {
 
       auth = new String(Base64.encode(auth.getBytes()));
       connection.addRequestProperty(header,
-                                    PREFIX_BASIC_AUTHENTICATION.concat(auth));
+        PREFIX_BASIC_AUTHENTICATION.concat(auth));
     }
   }
 
    * @param connection
    */
   private void appendHeaders(Map<String, List<String>> headers,
-                             URLConnection connection)
+    URLConnection connection)
   {
     if (Util.isNotEmpty(headers))
     {
    * @throws IOException
    */
   private void appendPostParameter(HttpURLConnection connection,
-                                   Map<String, List<String>> parameters)
-          throws IOException
+    Map<String, List<String>> parameters)
+    throws IOException
   {
     if (Util.isNotEmpty(parameters))
     {
    * @param connection
    */
   private void applySSLSettings(HttpRequest request,
-                                HttpsURLConnection connection)
+    HttpsURLConnection connection)
   {
     if (request.isDisableCertificateValidation())
     {
    * @throws IOException
    */
   private HttpURLConnection openConnection(HttpRequest request, String spec)
-          throws IOException
+    throws IOException
   {
     return openConnection(request, new URL(spec));
   }
    * @throws IOException
    */
   private HttpURLConnection openConnection(HttpRequest request, URL url)
-          throws IOException
+    throws IOException
   {
     if (request == null)
     {
+
       // TODO improve
       request = new HttpRequest(url.toExternalForm());
     }
 
     HttpURLConnection connection = null;
 
-    if (!request.isIgnoreProxySettings() && configuration.isEnableProxy())
+    if (!request.isIgnoreProxySettings()
+      && Proxies.isEnabled(configuration, url))
     {
       if (logger.isDebugEnabled())
       {
         logger.debug("fetch '{}' using proxy {}:{}",
-                     new Object[] { url.toExternalForm(),
-                                    configuration.getProxyServer(),
-                                    configuration.getProxyPort() });
+          new Object[] { url.toExternalForm(),
+          configuration.getProxyServer(), configuration.getProxyPort() });
       }
 
       SocketAddress address =
         new InetSocketAddress(configuration.getProxyServer(),
-                              configuration.getProxyPort());
+          configuration.getProxyPort());
 
       connection =
         (HttpURLConnection) url.openConnection(new Proxy(Proxy.Type.HTTP,
       String password = request.getPassword();
 
       appendBasicAuthHeader(connection, HEADER_AUTHORIZATION, username,
-                            password);
+        password);
     }
 
     connection.setRequestProperty(HEADER_ACCEPT_ENCODING,
-                                  HEADER_ACCEPT_ENCODING_VALUE);
-    connection.setRequestProperty(
-        HEADER_USERAGENT, HEADER_USERAGENT_VALUE.concat(context.getVersion()));
+      HEADER_ACCEPT_ENCODING_VALUE);
+    connection.setRequestProperty(HEADER_USERAGENT,
+      HEADER_USERAGENT_VALUE.concat(context.getVersion()));
 
     String username = configuration.getProxyUser();
     String password = configuration.getProxyPassword();
 
     appendBasicAuthHeader(connection, HEADER_PROXY_AUTHORIZATION, username,
-                          password);
+      password);
 
     return connection;
   }

scm-webapp/src/main/java/sonia/scm/plugin/AetherPluginHandler.java

 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Marshaller;
+import sonia.scm.net.Proxies;
 
 /**
  *
       RemoteRepository rr = new RemoteRepository(repository.getId(), "default",
                               repository.getUrl());
 
-      if (configuration.isEnableProxy())
+      if (Proxies.isEnabled(configuration, rr.getHost()))
       {
         Proxy proxy = DefaultProxySelector.createProxy(configuration);
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.