diff options
author | Christian Halstrick <christian.halstrick@sap.com> | 2016-10-14 14:20:40 +0200 |
---|---|---|
committer | Christian Halstrick <christian.halstrick@sap.com> | 2016-10-14 15:14:21 +0200 |
commit | 293e8beaccafced255ccd354adab36de0257352f (patch) | |
tree | 7525a536c94a43eac187d453205e211646071c36 /org.eclipse.jgit.pgm/src/org | |
parent | b8e3e194e3200adfb0c64a4d79b9bfbb0837b00c (diff) | |
download | jgit-293e8beaccafced255ccd354adab36de0257352f.tar.gz jgit-293e8beaccafced255ccd354adab36de0257352f.zip |
Fix JGit CLI to follow native git's interpretation of http_proxy...
Native git (as many other tools) interprets the environment variables
http_proxy, HTTP_PROXY, ... in a specific way. "http_proxy" has to be
lowercase while "https_proxy" can be lowercase or uppercase (means:
"HTTPS_PROXY"). Lowercase has precedence. This can be looked up in
"ENVIRONMENT" section of [1]. Teach JGit CLI to behave similar.
Additionally teach JGit not to interpret the environment variables if
the java process was explicitly started with the system properties
telling JVM which proxy to use. A call like "http_proxy=proxy1 java
-Dhttp.proxyHost=proxy2 ..." should use proxy2 as proxy.
[1] https://curl.haxx.se/docs/manpage.html
Change-Id: I2ad78f209792bf8f1285cf2f8ada8ae0c28f8e5a
Diffstat (limited to 'org.eclipse.jgit.pgm/src/org')
-rw-r--r-- | org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java | 21 |
1 files changed, 16 insertions, 5 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 3ddee36e3b..67a641db86 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 @@ -343,17 +343,28 @@ public class Main { * <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. + * utilities to configure the JRE before the first request is sent. The + * information found in the environment variables is copied to the + * associated system properties. This is not done when the system properties + * are already set. The default way of telling java programs about proxies + * (the system properties) takes precedence over environment variables. * * @throws MalformedURLException * the value in <code>http_proxy</code> or * <code>https_proxy</code> is unsupportable. */ - private static void configureHttpProxy() throws MalformedURLException { + static void configureHttpProxy() throws MalformedURLException { 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; + if (System.getProperty(protocol + ".proxyHost") != null) { //$NON-NLS-1$ + continue; + } + String s = System.getenv(protocol + "_proxy"); //$NON-NLS-1$ + if (s == null && protocol.equals("https")) { + s = System.getenv("HTTPS_PROXY"); //$NON-NLS-1$ + } + if (s == null || s.equals("")) { //$NON-NLS-1$ + continue; + } final URL u = new URL( (s.indexOf("://") == -1) ? protocol + "://" + s : s); //$NON-NLS-1$ //$NON-NLS-2$ |