mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-10 02:26:18 +00:00
[FIXED JENKINS-5271] Tools download does not appear to respect proxy settings.
This commit is contained in:
1 parent
ce7300cdf6
commit
9207c21f37
2 files changed
+27
-1
No files matched your search
@@ -40,6 +40,8 @@ import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import java.io.InputStream;
|
||||
import org.jvnet.robust_http_client.RetryableHttpStream;
|
||||
|
||||
/**
|
||||
* HTTP proxy configuration.
|
||||
@@ -162,6 +164,30 @@ public final class ProxyConfiguration implements Saveable {
|
||||
|
||||
return con;
|
||||
}
|
||||
|
||||
public static InputStream getInputStream(URL url) throws IOException {
|
||||
Jenkins h = Jenkins.getInstance(); // this code might run on slaves
|
||||
final ProxyConfiguration p = (h != null) ? h.proxy : null;
|
||||
if (p == null)
|
||||
return new RetryableHttpStream(url);
|
||||
|
||||
InputStream is = new RetryableHttpStream(url, p.createProxy());
|
||||
if (p.getUserName() != null) {
|
||||
// Add an authenticator which provides the credentials for proxy authentication
|
||||
Authenticator.setDefault(new Authenticator() {
|
||||
|
||||
@Override
|
||||
public PasswordAuthentication getPasswordAuthentication() {
|
||||
if (getRequestorType() != RequestorType.PROXY) {
|
||||
return null;
|
||||
}
|
||||
return new PasswordAuthentication(p.getUserName(), p.getPassword().toCharArray());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return is;
|
||||
}
|
||||
|
||||
private static final XStream XSTREAM = new XStream2();
|
||||
|
||||
|
||||
Reference in new issue
Block a user