Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #37 #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/main/java/com/xiaomitool/v2/tasks/DownloadTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class DownloadTask extends Task {
private File destination;
private Map<String, String> headers;
private long totalSize = 0, downloaded;
private int redirectDepth = 0;

public DownloadTask(UpdateListener listener, String url, String fileOutput) {
this(listener, url, fileOutput == null ? null : new File(fileOutput));
Expand Down Expand Up @@ -57,7 +58,13 @@ protected void startInternal() {
} catch (CustomHttpException e) {
error(e);
}
if (responseCode == 302) {
if (responseCode > 299 && responseCode < 399) {
if (redirectDepth > 10) {
error(new CustomHttpException("Too many redirects. Trying to reach " + url));

return;
}

String location;
try {
location = request.getResponseHeaders().get("location").get(0);
Expand All @@ -66,6 +73,7 @@ protected void startInternal() {
return;
}
url = location;
redirectDepth++;
startInternal();
return;
} else if (responseCode != 200) {
Expand Down