lingochamp / lingochamp/FileDownloader

1.7.7版本,下载出现412错误,设置忽略Etag,出现提示后端错误,但下载链接是亚马逊云,这个链接在其他下载工具是可以正常下载的

Open
#1,376 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
11.1k
Forks
2.2k
PR merge metrics
No merged PRs in 30d

Description

FileDownloader
.setupOnApplicationOnCreate(application)
.connectionCreator(FileDownloadUrlConnection.Creator(FileDownloadUrlConnection.Configuration()
.connectTimeout(15000) // set connection timeout.
.readTimeout(15000) // set read timeout.
))
.connectionCountAdapter { _, _, _, _ -> 1 }
.commit()
以上设置 出现421错误:
Connection failed with request[{If-Match=["9b09ab4bfa1125950b26ea93610dc487-26"], Range=[bytes=354903012-], User-Agent=[FileDownloader/1.7.7]}] response[{null=[HTTP/1.1 412 Precondition Failed], Connection=[keep-alive], Content-Type=[application/xml], Date=[Mon, 08 Feb 2021 03:24:03 GMT], Server=[AmazonS3], Transfer-Encoding=[chunked], Via=[1.1 34bd50b1d81b6dab6060e9282ae29c40.cloudfront.net (CloudFront)], X-Amz-Cf-Id=[0_oKujlpTXrW5ogwQBy5jFkxs-sIapcZ59_MqvGVU4NTCkQS19vPPA==], X-Amz-Cf-Pop=[HKG54-C1], X-Android-Received-Millis=[1612754643879], X-Android-Response-Source=[NETWORK 412], X-Android-Selected-Protocol=[http/1.1], X-Android-Sent-Millis=[1612754642996], X-Cache=[Error from cloudfront]}] http-state[412] on task[1763934570-4], which is changed after verify connection, so please try again

所以,修改了配置,忽略Etag:
FileDownloader.setupOnApplicationOnCreate(application)
.connectionCreator(object : FileDownloadUrlConnection
.Creator(FileDownloadUrlConnection.Configuration()
.connectTimeout(15_000) // set connection timeout.
.readTimeout(15_000) // set read timeout.
) {
override fun create(originUrl: String) : FileDownloadConnection {
return NoEtagFileDownloadUrlConnection(originUrl)
} })
.commit()

public class NoEtagFileDownloadUrlConnection extends FileDownloadUrlConnection {

public NoEtagFileDownloadUrlConnection(String originUrl, Configuration configuration) throws IOException {
super(originUrl, configuration);
}

public NoEtagFileDownloadUrlConnection(URL url, Configuration configuration) throws IOException {
super(url, configuration);
}

public NoEtagFileDownloadUrlConnection(String originUrl) throws IOException {
super(originUrl);
}

@Override
public void addHeader(String name, String value) {
if ("If-Match".equals(name)) {
return;
}
super.addHeader(name, value);
}

}

但是,出现了其他异常:
require range[354903012-) with contentLength(88725753), but the backend response contentLength is 88698155 on downloadId[1763934570]-connectionIndex[4], please ask your backend dev to fix such problem.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with FileDownloadUrlConnection and the connection setup shown in the report, then trace handling of If-Match, HTTP 412 responses, and ranged downloads. Reproduce the reported Amazon S3 or CloudFront response if possible and inspect how the expected and backend content lengths are calculated. Done means the reported resume-download failure is explained and covered by a verified fix or a documented backend incompatibility.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.