@@ -50,9 +50,11 @@ public class HttpConnectionManager {
50
50
private static Logger log = LogManager .getLogger (HttpConnectionManager .class );
51
51
private static final String userAgent ;
52
52
private static final int connectTimeout ;
53
+ private static final int maxRedirectNumber ;
53
54
private final URL requestURL ;
54
55
private final String id ;
55
56
57
+
56
58
static {
57
59
final String defaultUserAgent = String .format (
58
60
"ArduinoIDE/%s (%s; %s; %s; %s) Java/%s (%s)" ,
@@ -75,6 +77,17 @@ public class HttpConnectionManager {
75
77
"Cannot parse the http.connection_timeout configuration switch to default {} milliseconds" , connectTimeoutFromConfig , e .getCause ());
76
78
}
77
79
connectTimeout = connectTimeoutFromConfig ;
80
+ // Set by default 20 max redirect to follow
81
+ int maxRedirectNumberConfig = 20 ;
82
+ try {
83
+ maxRedirectNumberConfig =
84
+ Integer .parseInt (
85
+ PreferencesData .get ("http.max_redirect_number" , "20" ));
86
+ } catch (NumberFormatException e ) {
87
+ log .warn (
88
+ "Cannot parse the http.max_redirect_number configuration switch to default {}" , maxRedirectNumberConfig , e .getCause ());
89
+ }
90
+ maxRedirectNumber = maxRedirectNumberConfig ;
78
91
}
79
92
80
93
public HttpConnectionManager (URL requestURL ) {
@@ -102,7 +115,7 @@ public HttpURLConnection makeConnection()
102
115
103
116
private HttpURLConnection makeConnection (URL requestURL , int movedTimes ,
104
117
Consumer <HttpURLConnection > beforeConnection ) throws IOException , URISyntaxException , ScriptException , NoSuchMethodException {
105
- if (movedTimes > 3 ) {
118
+ if (movedTimes > maxRedirectNumber ) {
106
119
log .warn ("Too many redirect " + requestURL );
107
120
throw new IOException ("Too many redirect " + requestURL );
108
121
}
0 commit comments