From 51fc9253ef1f44fadbeabb1b8fec8976bf5177ad Mon Sep 17 00:00:00 2001 From: Jacksgong Date: Thu, 22 Jun 2017 23:25:27 +0800 Subject: [PATCH] feat: do not carry etag on separate downloading when the task from very beginning to avoid precondition failed on separate downloading --- .../download/DownloadLaunchRunnable.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/library/src/main/java/com/liulishuo/filedownloader/download/DownloadLaunchRunnable.java b/library/src/main/java/com/liulishuo/filedownloader/download/DownloadLaunchRunnable.java index d4948576..72602652 100644 --- a/library/src/main/java/com/liulishuo/filedownloader/download/DownloadLaunchRunnable.java +++ b/library/src/main/java/com/liulishuo/filedownloader/download/DownloadLaunchRunnable.java @@ -431,9 +431,9 @@ private void handleFirstConnected(Map> requestHeader, if (isPreconditionFailed) { // the file on remote is changed - if (acceptPartial) { + if (isResumeAvailableOnDB) { FileDownloadLog.w(this, "there is precondition failed on this request[%d] " + - "with old etag[%s] != new etag[%s], but the response code is %d", + "with old etag[%s]、new etag[%s]、response code is %d", id, oldEtag, newEtag, code); } @@ -560,6 +560,10 @@ private void fetchWithMultipleConnection(final List connectionM } long totalOffset = 0; + + // why not with etag when not resume from the database? because do this can avoid + // precondition failed on separate downloading. + final boolean withEtag = isResumeAvailableOnDB; for (ConnectionModel connectionModel : connectionModelList) { totalOffset += (connectionModel.getCurrentOffset() - connectionModel.getStartOffset()); @@ -584,7 +588,7 @@ private void fetchWithMultipleConnection(final List connectionM .setConnectionIndex(connectionModel.getIndex()) .setCallback(this) .setUrl(url) - .setEtag(etag) + .setEtag(withEtag ? etag : null) .setHeader(userRequestHeader) .setWifiRequired(isWifiRequired) .setConnectionModel(connectionProfile)