Since http protocol is very complex, we provide 3 methods for downloading the specified objects. The 3 methods are:
a. Multi-threaded download: It must fulfill two preconditions. 1. support the "content-length" in the response. 2. support "range" header in the request headers.
b. Single-threaded download: When the servers do not support "range" header, we cannot get the partial contents for each thread. We can only use the single-threaded download.
C. Un-determinated download: When we cannot get the exact file length from the "content-length" header in the response, we can only download the object in this mode. And the EOF will be the flag for the end of the download process.
In the current implementation, we use the following process to do the method selection:
1. Send a head/get method to the specified object's url
2. Check whether the response contains the "content-length" header.
2.a) If it contains "content-length" header, send another request which contains "range: 1-2" to test whether it supports "range" header
2.a.1) If the response code is 203 (partial content), select multi-threaded download
2.a.2) If the response code is 200 (ok), select single-threaded download
2.b) If it does not contains "content-length" header, we can just use undeterminated-download method.
In our implementation, we use "FixLengthHttp***" to identify classes used in "multi-theaded" and "single-threaded" download. And we use "VarLengthHttp***" to identify classes used in "undeterminated download". |