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: download error with some file url without content range in it's … #472

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
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.liulishuo.okdownload.DownloadListener;
import com.liulishuo.okdownload.DownloadTask;
import com.liulishuo.okdownload.OkDownload;
import com.liulishuo.okdownload.core.Util;
import com.liulishuo.okdownload.core.breakpoint.BreakpointInfo;
import com.liulishuo.okdownload.core.connection.DownloadConnection;
import com.liulishuo.okdownload.core.exception.DownloadSecurityException;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.util.HashMap;
Expand Down Expand Up @@ -238,9 +236,13 @@ private static boolean isAcceptRange(@NonNull DownloadConnection.Connected conne
}

private static long findInstanceLength(DownloadConnection.Connected connected) {
// Content-Range
final long instanceLength = parseContentRangeFoInstanceLength(
//content length
long instanceLength = convertContentLengthString(connected.getResponseHeaderField(CONTENT_LENGTH));
if (instanceLength == CHUNKED_CONTENT_LENGTH){
// Content-Range
instanceLength = parseContentRangeFoInstanceLength(
connected.getResponseHeaderField(CONTENT_RANGE));
}
if (instanceLength != CHUNKED_CONTENT_LENGTH) return instanceLength;

// chunked on here
Expand All @@ -254,6 +256,16 @@ private static long findInstanceLength(DownloadConnection.Connected connected) {
return CHUNKED_CONTENT_LENGTH;
}

public static long convertContentLengthString(String s) {
if (s == null) return -1;
try {
return Long.parseLong(s);
} catch (NumberFormatException e) {
return -1;
}
}


boolean isNeedTrialHeadMethodForInstanceLength(
long oldInstanceLength, @NonNull DownloadConnection.Connected connected) {
if (oldInstanceLength != CHUNKED_CONTENT_LENGTH) {
Expand Down