Skip to content
Permalink
Browse files
[FIXED JENKINS-5271] Tools download does not appear to respect proxy …
…settings.

(cherry picked from commit 9207c21)
  • Loading branch information
ssogabe authored and kohsuke committed Oct 21, 2011
1 parent 9a3bea3 commit 9db0b51c1605f91ba17694a8f34746bdf0a3369d
Showing with 27 additions and 1 deletion.
  1. +1 −1 core/src/main/java/hudson/FilePath.java
  2. +26 −0 core/src/main/java/hudson/ProxyConfiguration.java
@@ -630,7 +630,7 @@ public boolean installIfNecessaryFrom(URL archive, TaskListener listener, String
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.URLConnection;

import com.thoughtworks.xstream.XStream;
import java.io.InputStream;
import org.jvnet.robust_http_client.RetryableHttpStream;

/**
* HTTP proxy configuration.
@@ -158,6 +160,30 @@ public PasswordAuthentication getPasswordAuthentication() {
}
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();

0 comments on commit 9db0b51

Please sign in to comment.