diff options
author | Christian Halstrick <christian.halstrick@sap.com> | 2015-07-24 14:05:37 +0200 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2015-07-24 22:54:56 +0200 |
commit | c3a073527ea0d6b0f5cbdef10dfd107de0e1c3d8 (patch) | |
tree | 9cbdf295941b95753c57e9d0721b38919460620a /org.eclipse.jgit.pgm | |
parent | 1196dd0643222250677ec24dec40566dfc643983 (diff) | |
download | jgit-c3a073527ea0d6b0f5cbdef10dfd107de0e1c3d8.tar.gz jgit-c3a073527ea0d6b0f5cbdef10dfd107de0e1c3d8.zip |
Honor also https_proxy environment variable
In addition to honor the http_proxy variable for setting a proxy for
http JGit should also honor the https_proxy variable to set a similar
proxy for https traffic
Bug: 473365
Change-Id: I1002cb575e26cd842bf81ad751ec7c267b585ce2
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.pgm')
-rw-r--r-- | org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java | 56 |
1 files changed, 31 insertions, 25 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java index 7151de794d..854cc68fbc 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java @@ -291,39 +291,45 @@ public class Main { /** * Configure the JRE's standard HTTP based on <code>http_proxy</code>. * <p> - * The popular libcurl library honors the <code>http_proxy</code> - * environment variable as a means of specifying an HTTP proxy for requests - * made behind a firewall. This is not natively recognized by the JRE, so - * this method can be used by command line utilities to configure the JRE - * before the first request is sent. + * The popular libcurl library honors the <code>http_proxy</code>, + * <code>https_proxy</code> environment variables as a means of specifying + * an HTTP/S proxy for requests made behind a firewall. This is not natively + * recognized by the JRE, so this method can be used by command line + * utilities to configure the JRE before the first request is sent. * * @throws MalformedURLException - * the value in <code>http_proxy</code> is unsupportable. + * the value in <code>http_proxy</code> or + * <code>https_proxy</code> is unsupportable. */ private static void configureHttpProxy() throws MalformedURLException { - final String s = System.getenv("http_proxy"); //$NON-NLS-1$ - if (s == null || s.equals("")) //$NON-NLS-1$ - return; + for (String protocol : new String[] { "http", "https" }) { //$NON-NLS-1$ //$NON-NLS-2$ + final String s = System.getenv(protocol + "_proxy"); //$NON-NLS-1$ + if (s == null || s.equals("")) //$NON-NLS-1$ + return; - final URL u = new URL((s.indexOf("://") == -1) ? "http://" + s : s); //$NON-NLS-1$ //$NON-NLS-2$ - if (!"http".equals(u.getProtocol())) //$NON-NLS-1$ - throw new MalformedURLException(MessageFormat.format(CLIText.get().invalidHttpProxyOnlyHttpSupported, s)); + final URL u = new URL( + (s.indexOf("://") == -1) ? protocol + "://" + s : s); //$NON-NLS-1$ //$NON-NLS-2$ + if (!u.getProtocol().startsWith("http")) //$NON-NLS-1$ + throw new MalformedURLException(MessageFormat.format( + CLIText.get().invalidHttpProxyOnlyHttpSupported, s)); - final String proxyHost = u.getHost(); - final int proxyPort = u.getPort(); + final String proxyHost = u.getHost(); + final int proxyPort = u.getPort(); - System.setProperty("http.proxyHost", proxyHost); //$NON-NLS-1$ - if (proxyPort > 0) - System.setProperty("http.proxyPort", String.valueOf(proxyPort)); //$NON-NLS-1$ + System.setProperty(protocol + ".proxyHost", proxyHost); //$NON-NLS-1$ + if (proxyPort > 0) + System.setProperty(protocol + ".proxyPort", //$NON-NLS-1$ + String.valueOf(proxyPort)); - final String userpass = u.getUserInfo(); - if (userpass != null && userpass.contains(":")) { //$NON-NLS-1$ - final int c = userpass.indexOf(':'); - final String user = userpass.substring(0, c); - final String pass = userpass.substring(c + 1); - CachedAuthenticator - .add(new CachedAuthenticator.CachedAuthentication( - proxyHost, proxyPort, user, pass)); + final String userpass = u.getUserInfo(); + if (userpass != null && userpass.contains(":")) { //$NON-NLS-1$ + final int c = userpass.indexOf(':'); + final String user = userpass.substring(0, c); + final String pass = userpass.substring(c + 1); + CachedAuthenticator.add( + new CachedAuthenticator.CachedAuthentication(proxyHost, + proxyPort, user, pass)); + } } } } |