1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-20 09:52:13 +01:00

Increase the redirect to follow to 20

Add the possibility to configure them `http.max_redirect_number`
This commit is contained in:
Mattia Bertorello 2019-07-11 14:36:45 +02:00
parent 58fc5a5011
commit dde5668b27
No known key found for this signature in database
GPG Key ID: CE1FB2BE91770F24

View File

@ -50,9 +50,11 @@ public class HttpConnectionManager {
private static Logger log = LogManager.getLogger(HttpConnectionManager.class);
private static final String userAgent;
private static final int connectTimeout;
private static final int maxRedirectNumber;
private final URL requestURL;
private final String id;
static {
final String defaultUserAgent = String.format(
"ArduinoIDE/%s (%s; %s; %s; %s) Java/%s (%s)",
@ -75,6 +77,17 @@ public class HttpConnectionManager {
"Cannot parse the http.connection_timeout configuration switch to default {} milliseconds", connectTimeoutFromConfig, e.getCause());
}
connectTimeout = connectTimeoutFromConfig;
// Set by default 20 max redirect to follow
int maxRedirectNumberConfig = 20;
try {
maxRedirectNumberConfig =
Integer.parseInt(
PreferencesData.get("http.max_redirect_number", "20"));
} catch (NumberFormatException e) {
log.warn(
"Cannot parse the http.max_redirect_number configuration switch to default {}", maxRedirectNumberConfig, e.getCause());
}
maxRedirectNumber = maxRedirectNumberConfig;
}
public HttpConnectionManager(URL requestURL) {
@ -102,7 +115,7 @@ public class HttpConnectionManager {
private HttpURLConnection makeConnection(URL requestURL, int movedTimes,
Consumer<HttpURLConnection> beforeConnection) throws IOException, URISyntaxException, ScriptException, NoSuchMethodException {
if (movedTimes > 3) {
if (movedTimes > maxRedirectNumber) {
log.warn("Too many redirect " + requestURL);
throw new IOException("Too many redirect " + requestURL);
}