3232import cc .arduino .net .CustomProxySelector ;
3333import org .apache .commons .codec .binary .Base64 ;
3434import org .apache .commons .compress .utils .IOUtils ;
35+
36+ import processing .app .BaseNoGui ;
3537import processing .app .PreferencesData ;
3638
3739import 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