From 1f3c8b9f6cda8a94756d19bf029e0a997e75fee9 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 8 Mar 2016 11:11:52 +0100 Subject: [PATCH] Set correct user-agent when performing HTTP requests --- .../src/cc/arduino/utils/network/FileDownloader.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arduino-core/src/cc/arduino/utils/network/FileDownloader.java b/arduino-core/src/cc/arduino/utils/network/FileDownloader.java index 2702767db..314ec0723 100644 --- a/arduino-core/src/cc/arduino/utils/network/FileDownloader.java +++ b/arduino-core/src/cc/arduino/utils/network/FileDownloader.java @@ -32,6 +32,8 @@ package cc.arduino.utils.network; import cc.arduino.net.CustomProxySelector; import org.apache.commons.codec.binary.Base64; import org.apache.commons.compress.utils.IOUtils; + +import processing.app.BaseNoGui; import processing.app.PreferencesData; import java.io.File; @@ -66,12 +68,15 @@ public class FileDownloader extends Observable { private final File outputFile; private InputStream stream = null; private Exception error; + private String userAgent; public FileDownloader(URL url, File file) { downloadUrl = url; outputFile = file; downloaded = 0; initialSize = 0; + userAgent = "ArduinoIDE/" + BaseNoGui.VERSION_NAME + " Java/" + + System.getProperty("java.version"); } public long getInitialSize() { @@ -151,7 +156,7 @@ public class FileDownloader extends Observable { } HttpURLConnection connection = (HttpURLConnection) downloadUrl.openConnection(proxy); - + connection.setRequestProperty("User-agent", userAgent); if (downloadUrl.getUserInfo() != null) { String auth = "Basic " + new String(new Base64().encode(downloadUrl.getUserInfo().getBytes())); connection.setRequestProperty("Authorization", auth); @@ -172,6 +177,7 @@ public class FileDownloader extends Observable { // open the new connnection again connection = (HttpURLConnection) newUrl.openConnection(proxy); + connection.setRequestProperty("User-agent", userAgent); if (downloadUrl.getUserInfo() != null) { String auth = "Basic " + new String(new Base64().encode(downloadUrl.getUserInfo().getBytes())); connection.setRequestProperty("Authorization", auth);