提交 9207c21f 编写于 作者: S Seiji Sogabe 提交者: Kohsuke Kawaguchi

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

上级 ce7300cd
......@@ -655,7 +655,7 @@ public final class FilePath implements Serializable {
listener.getLogger().println(message);
// for HTTP downloads, enable automatic retry for added resilience
InputStream in = archive.getProtocol().equals("http") ? new RetryableHttpStream(archive) : con.getInputStream();
InputStream in = archive.getProtocol().equals("http") ? ProxyConfiguration.getInputStream(archive) : con.getInputStream();
CountingInputStream cis = new CountingInputStream(in);
try {
if(archive.toExternalForm().endsWith(".zip"))
......
......@@ -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();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册