Skip to content

Commit

Permalink
feat: do not carry etag on separate downloading when the task from ve…
Browse files Browse the repository at this point in the history
…ry beginning to avoid precondition failed on separate downloading
  • Loading branch information
Jacksgong committed Jun 22, 2017
1 parent fbbbfcb commit 51fc925
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,9 @@ private void handleFirstConnected(Map<String, List<String>> 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);
}

Expand Down Expand Up @@ -560,6 +560,10 @@ private void fetchWithMultipleConnection(final List<ConnectionModel> 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());

Expand All @@ -584,7 +588,7 @@ private void fetchWithMultipleConnection(final List<ConnectionModel> connectionM
.setConnectionIndex(connectionModel.getIndex())
.setCallback(this)
.setUrl(url)
.setEtag(etag)
.setEtag(withEtag ? etag : null)
.setHeader(userRequestHeader)
.setWifiRequired(isWifiRequired)
.setConnectionModel(connectionProfile)
Expand Down

0 comments on commit 51fc925

Please sign in to comment.