Skip to content

Commit dde5668

Browse files
author
Mattia Bertorello
committed
Increase the redirect to follow to 20
Add the possibility to configure them `http.max_redirect_number`
1 parent 58fc5a5 commit dde5668

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

Diff for: arduino-core/src/cc/arduino/utils/network/HttpConnectionManager.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ public class HttpConnectionManager {
5050
private static Logger log = LogManager.getLogger(HttpConnectionManager.class);
5151
private static final String userAgent;
5252
private static final int connectTimeout;
53+
private static final int maxRedirectNumber;
5354
private final URL requestURL;
5455
private final String id;
5556

57+
5658
static {
5759
final String defaultUserAgent = String.format(
5860
"ArduinoIDE/%s (%s; %s; %s; %s) Java/%s (%s)",
@@ -75,6 +77,17 @@ public class HttpConnectionManager {
7577
"Cannot parse the http.connection_timeout configuration switch to default {} milliseconds", connectTimeoutFromConfig, e.getCause());
7678
}
7779
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;
7891
}
7992

8093
public HttpConnectionManager(URL requestURL) {
@@ -102,7 +115,7 @@ public HttpURLConnection makeConnection()
102115

103116
private HttpURLConnection makeConnection(URL requestURL, int movedTimes,
104117
Consumer<HttpURLConnection> beforeConnection) throws IOException, URISyntaxException, ScriptException, NoSuchMethodException {
105-
if (movedTimes > 3) {
118+
if (movedTimes > maxRedirectNumber) {
106119
log.warn("Too many redirect " + requestURL);
107120
throw new IOException("Too many redirect " + requestURL);
108121
}

0 commit comments

Comments
 (0)