[FIXED JENKINS-5271] Tools download does not appear to respect proxy settings.

This commit is contained in:
Seiji Sogabe authored and Kohsuke Kawaguchi committed 2011-09-18 16:16:38 -07:00
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();