Skip to content

Commit

Permalink
Fix #766: ProxyOptions for Vert.X Downloader (#767)
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware authored Sep 18, 2024
1 parent a3c9f5b commit fa12ef3
Showing 1 changed file with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.vertx.core.buffer.Buffer;
import io.vertx.core.file.AsyncFile;
import io.vertx.core.file.OpenOptions;
import io.vertx.core.net.ProxyOptions;
import io.vertx.ext.web.client.HttpRequest;
import io.vertx.ext.web.client.HttpResponse;
import io.vertx.ext.web.client.WebClient;
Expand All @@ -31,11 +32,31 @@ public class VertxFileDownloader implements FileDownloader {

public VertxFileDownloader(Vertx vertx) {
this.vertx = vertx;
webClient = WebClient.create(vertx, new WebClientOptions()

String proxyHost = System.getProperty("http.proxyHost");
String proxyPort = System.getProperty("http.proxyPort");
String proxyUser = System.getProperty("http.proxyUser");
String proxyPassword = System.getProperty("http.proxyPassword");

WebClientOptions options = new WebClientOptions()
.setSsl(true)
.setFollowRedirects(true)
.setTrustAll(true)
.setKeepAlive(true));
.setKeepAlive(true);

// Set the proxy if it's configured
if (proxyHost != null && proxyPort != null) {
options.setProxyOptions(new ProxyOptions()
.setHost(proxyHost)
.setPort(Integer.parseInt(proxyPort)));

// Optionally, add authentication
if (proxyUser != null && proxyPassword != null) {
options.getProxyOptions().setUsername(proxyUser).setPassword(proxyPassword);
}
}

this.webClient = WebClient.create(vertx, options);
}

public void download(String downloadUrl, String destination, String userName, String password) throws DownloadException {
Expand Down

0 comments on commit fa12ef3

Please sign in to comment.