1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-17 22:23:10 +03:00

Boards/Lib managers: use system proxy settings (got rid of our proxy settings

in File > Preferences)
This commit is contained in:
Federico Fissore
2015-06-03 10:24:07 +02:00
parent e9d66015a4
commit 0cb6b48e24
5 changed files with 40 additions and 394 deletions

View File

@ -36,9 +36,7 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.net.HttpURLConnection;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.*;
import java.util.Observable;
public class FileDownloader extends Observable {
@ -122,29 +120,9 @@ public class FileDownloader extends Observable {
setStatus(Status.CONNECTING);
System.getProperties().remove("http.proxyHost");
System.getProperties().remove("http.proxyPort");
System.getProperties().remove("https.proxyHost");
System.getProperties().remove("https.proxyPort");
System.getProperties().remove("http.proxyUser");
System.getProperties().remove("http.proxyPassword");
Proxy proxy = ProxySelector.getDefault().select(downloadUrl.toURI()).get(0);
if (PreferencesData.has("proxy.http.server") && PreferencesData.get("proxy.http.server") != null && !PreferencesData.get("proxy.http.server").equals("")) {
System.getProperties().put("http.proxyHost", PreferencesData.get("proxy.http.server"));
System.getProperties().put("http.proxyPort", PreferencesData.get("proxy.http.port"));
}
if (PreferencesData.has("proxy.https.server") && PreferencesData.get("proxy.https.server") != null && !PreferencesData.get("proxy.https.server").equals("")) {
System.getProperties().put("https.proxyHost", PreferencesData.get("proxy.https.server"));
System.getProperties().put("https.proxyPort", PreferencesData.get("proxy.https.port"));
}
if (PreferencesData.has("proxy.user") && PreferencesData.get("proxy.user") != null && !PreferencesData.get("proxy.user").equals("")) {
System.getProperties().put("http.proxyUser", PreferencesData.get("proxy.user"));
System.getProperties().put("http.proxyPassword", PreferencesData.get("proxy.password"));
System.getProperties().put("https.proxyUser", PreferencesData.get("proxy.user"));
System.getProperties().put("https.proxyPassword", PreferencesData.get("proxy.password"));
}
HttpURLConnection connection = (HttpURLConnection) downloadUrl.openConnection();
HttpURLConnection connection = (HttpURLConnection) downloadUrl.openConnection(proxy);
if (downloadUrl.getUserInfo() != null) {
String auth = "Basic " + new String(new Base64().encode(downloadUrl.getUserInfo().getBytes()));
@ -160,10 +138,12 @@ public class FileDownloader extends Observable {
int resp = connection.getResponseCode();
if (resp == HttpURLConnection.HTTP_MOVED_PERM || resp == HttpURLConnection.HTTP_MOVED_TEMP) {
String newUrl = connection.getHeaderField("Location");
URL newUrl = new URL(connection.getHeaderField("Location"));
proxy = ProxySelector.getDefault().select(newUrl.toURI()).get(0);
// open the new connnection again
connection = (HttpURLConnection) new URL(newUrl).openConnection();
connection = (HttpURLConnection) newUrl.openConnection(proxy);
if (downloadUrl.getUserInfo() != null) {
String auth = "Basic " + new String(new Base64().encode(downloadUrl.getUserInfo().getBytes()));
connection.setRequestProperty("Authorization", auth);

View File

@ -742,8 +742,10 @@ public class BaseNoGui {
}
static public void main(String args[]) throws Exception {
if (args.length == 0)
if (args.length == 0) {
showError(_("No parameters"), _("No command line parameters found"), null);
}
System.setProperty("java.net.useSystemProxies", "true");
Runtime.getRuntime().addShutdownHook(new Thread(DeleteFilesOnShutdown.INSTANCE));