Skip to content

Commit

Permalink
Increase the redirect to follow to 20
Browse files Browse the repository at this point in the history
Add the possibility to configure them `http.max_redirect_number`
  • Loading branch information
Mattia Bertorello committed Jul 11, 2019
1 parent 58fc5a5 commit dde5668
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand All @@ -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) {
Expand Down Expand Up @@ -102,7 +115,7 @@ public HttpURLConnection makeConnection()

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);
}
Expand Down

0 comments on commit dde5668

Please sign in to comment.