Skip to content

Commit 1f3c8b9

Browse files
committed
Set correct user-agent when performing HTTP requests
1 parent 60ba866 commit 1f3c8b9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

arduino-core/src/cc/arduino/utils/network/FileDownloader.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import cc.arduino.net.CustomProxySelector;
3333
import org.apache.commons.codec.binary.Base64;
3434
import org.apache.commons.compress.utils.IOUtils;
35+
36+
import processing.app.BaseNoGui;
3537
import processing.app.PreferencesData;
3638

3739
import java.io.File;
@@ -66,12 +68,15 @@ public enum Status {
6668
private final File outputFile;
6769
private InputStream stream = null;
6870
private Exception error;
71+
private String userAgent;
6972

7073
public FileDownloader(URL url, File file) {
7174
downloadUrl = url;
7275
outputFile = file;
7376
downloaded = 0;
7477
initialSize = 0;
78+
userAgent = "ArduinoIDE/" + BaseNoGui.VERSION_NAME + " Java/"
79+
+ System.getProperty("java.version");
7580
}
7681

7782
public long getInitialSize() {
@@ -151,7 +156,7 @@ private void downloadFile() throws InterruptedException {
151156
}
152157

153158
HttpURLConnection connection = (HttpURLConnection) downloadUrl.openConnection(proxy);
154-
159+
connection.setRequestProperty("User-agent", userAgent);
155160
if (downloadUrl.getUserInfo() != null) {
156161
String auth = "Basic " + new String(new Base64().encode(downloadUrl.getUserInfo().getBytes()));
157162
connection.setRequestProperty("Authorization", auth);
@@ -172,6 +177,7 @@ private void downloadFile() throws InterruptedException {
172177

173178
// open the new connnection again
174179
connection = (HttpURLConnection) newUrl.openConnection(proxy);
180+
connection.setRequestProperty("User-agent", userAgent);
175181
if (downloadUrl.getUserInfo() != null) {
176182
String auth = "Basic " + new String(new Base64().encode(downloadUrl.getUserInfo().getBytes()));
177183
connection.setRequestProperty("Authorization", auth);

0 commit comments

Comments
 (0)