Comments (5)
Thank you very much. Its working perfectly now.
from okdownload.
REASON
This URL response header can't meet HTTP 1.1 RFC 2616 and HTTP 1.1 RFC 7233 define, and violate it very far.
I debug okdownload on the sample project SingleActivity
with replacing with your provide URL, and get the following log:
As you can see, the request and response to the trial connection before split several blocks to downloading:
- Request header:
{range=[bytes=0-0]}
- Response header:
code[206]{accept-ranges=[bytes], access-control-allow-headers=[X-Parse-Master-Key, X-Parse-REST-API-Key, X-Parse-Javascript-Key, X-Parse-Application-Id, X-Parse-Client-Version, X-Parse-Session-Token, X-Requested-With, X-Parse-Revocable-Session, Content-Type], access-control-allow-methods=[GET,PUT,POST,DELETE,OPTIONS], access-control-allow-origin=[*], connection=[keep-alive], content-length=[1048577], content-range=[bytes 0-1048576/24030363], content-type=[video/mp4], date=[Sat, 07 Apr 2018 01:41:54 GMT], x-powered-by=[Express]}
So as page 5 of RFC 7233 said:
The first and last bytes only (bytes 0 and 9999):
bytes=0-0,-1
So, when the request with {range=[bytes=0-0]}
, the response would with content-length=[1]
what is only the first-byte length, so in here we can't get the instance length from content-length
because on the define with the request it is not the instance length, But on the response of your provide URL the response header is content-length=[1048577]
what is very wrong, and we can't use it, as define it is not the instance length. Then as the RFC 2616 defined, the content-range
would tell us the right instance length with content-range=[unit range/instant-length]
, and with your URL we got the instance length from content-range=[bytes 0-1048576/24030363]
is 24030363
, and then we use this instance length to split into several blocks to download this resources, but on the block two the input-stream from response body only provide 1048577
bytes data, so you occur such problem.
So I guess, the right response to your URL would contain content-length=[1], content-range=[bytes 0-0/1048576]
, but your response is content-length=[1048577], content-range=[bytes 0-1048576/24030363]
, as you can see: none of them are correct, and why don't we use content-length
of it directly? because as the RFC define, it is not the instance length, even if you don't provide content-range
field we also need use HEAD
method request to get the certain content-length
as the instance length.
Appendix
Why need to download with split several blocks?
Because of the most resource, one connection doesn't provide enough speed input-stream for it, so we split several blocks of it and use each independent connection to touch each block input-stream simultaneously to enhance the download speed.
Why there is a trial connection before split several blocks to downloading?
Because of before split-block, we need to know how many blocks do we need to split, then we need to know whether the resource support split block or not and the instance length of resource, and use GET
method request with {range=0-0}
or HEAD
method request for the trial connection is just for avoiding cache useless data on TCP receive window.
from okdownload.
Thanks for your response.
URL is not in my control. Which API should I use from your library?
from okdownload.
I think this resource has something special, it is like chunked resource but it response content-length
and content-range
without transfer-encoding=[chunked]
.
I tried the Url without {range=0-0}
and just raise an HTTP HEAD
request( without any addition request header), the response is: content-length=[24030363]
. So the instance-length is 24030363
.
REAL PROBLEM
As the Request-Range
define on the RFC 7233:
Additional examples, assuming a representation of length 10000:
o The final 500 bytes (byte offsets 9500-9999, inclusive):
bytes=-500
Or:
bytes=9500-
We think such as 9500-
is just means from 9500
to end
, but for the URL you provide it means 9500-1058075
(9500+1048576-1
), so I tried using especially range even for the last block the download is correct.
So consider this case we will add exactly range even for the last block to fix such problem on 1.0.1.
from okdownload.
Now, You can use v1.0.1-SNAPSHOT which handled this issue, and final release would be on v1.0.1.
from okdownload.
Related Issues (20)
- is OkDownload support config custom Executor?
- 断点下载的判断为什么没有使用If-Range呢 HOT 1
- 下载超过2G多大文件时,杀进程后,再次下载无法断点续传。 HOT 2
- 报错啦,求大佬支援 HOT 2
- The current offset on block-info isn't update correct, 104466100 != 106391228 on 3
- The current offset on block-info isn't update correct, 104466100 != 106391228 on 3 HOT 14
- 当文件存在时,如何覆盖当前文件下载 HOT 2
- How do I download and run this ? HOT 1
- TaskEnd while EachBlockProgress not always called
- 如何在杀了应用后,可以断点续传下载
- java.lang.IllegalStateException: The current store is com.liulishuo.okdownload.core.breakpoint.BreakpointStoreOnSQLite@11ffbcb not RemitStoreOnSQLite!
- Build Failed AGP8
- Resume failed because of RESPONSE_PRECONDITION_FAILED
- Android13 taskEnd: 1 ERROR java.io.IOException: Create parent folder failed!
- How to Download with Referer on Header HOT 1
- m.My/ HOT 1
- targetSDK升级到30后无法正常使用 HOT 10
- 不需要断点续传的单文件下载场景,可使用以下替代方案试一试
- https://m.facebook.com,au
- 当前url请求失败或者下载异常,如何通过备用url或者ip直连的方式重试, HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from okdownload.