Skip to content

Commit

Permalink
[FIXED JENKINS-5271] Tools download does not appear to respect proxy …
Browse files Browse the repository at this point in the history
…settings.
  • Loading branch information
ssogabe authored and kohsuke committed Sep 18, 2011
1 parent ce7300c commit 9207c21
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/FilePath.java
Expand Up @@ -655,7 +655,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"))
Expand Down
26 changes: 26 additions & 0 deletions core/src/main/java/hudson/ProxyConfiguration.java
Expand Up @@ -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.
Expand Down Expand Up @@ -162,6 +164,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();

Expand Down

0 comments on commit 9207c21

Please sign in to comment.