32
32
import cc .arduino .net .CustomProxySelector ;
33
33
import org .apache .commons .codec .binary .Base64 ;
34
34
import org .apache .commons .compress .utils .IOUtils ;
35
+
36
+ import processing .app .BaseNoGui ;
35
37
import processing .app .PreferencesData ;
36
38
37
39
import java .io .File ;
@@ -66,12 +68,15 @@ public enum Status {
66
68
private final File outputFile ;
67
69
private InputStream stream = null ;
68
70
private Exception error ;
71
+ private String userAgent ;
69
72
70
73
public FileDownloader (URL url , File file ) {
71
74
downloadUrl = url ;
72
75
outputFile = file ;
73
76
downloaded = 0 ;
74
77
initialSize = 0 ;
78
+ userAgent = "ArduinoIDE/" + BaseNoGui .VERSION_NAME + " Java/"
79
+ + System .getProperty ("java.version" );
75
80
}
76
81
77
82
public long getInitialSize () {
@@ -151,7 +156,7 @@ private void downloadFile() throws InterruptedException {
151
156
}
152
157
153
158
HttpURLConnection connection = (HttpURLConnection ) downloadUrl .openConnection (proxy );
154
-
159
+ connection . setRequestProperty ( "User-agent" , userAgent );
155
160
if (downloadUrl .getUserInfo () != null ) {
156
161
String auth = "Basic " + new String (new Base64 ().encode (downloadUrl .getUserInfo ().getBytes ()));
157
162
connection .setRequestProperty ("Authorization" , auth );
@@ -172,6 +177,7 @@ private void downloadFile() throws InterruptedException {
172
177
173
178
// open the new connnection again
174
179
connection = (HttpURLConnection ) newUrl .openConnection (proxy );
180
+ connection .setRequestProperty ("User-agent" , userAgent );
175
181
if (downloadUrl .getUserInfo () != null ) {
176
182
String auth = "Basic " + new String (new Base64 ().encode (downloadUrl .getUserInfo ().getBytes ()));
177
183
connection .setRequestProperty ("Authorization" , auth );
0 commit comments