1. Let me start with how download manager gets to know the size of the requesed file and if server supports resume download.
Similar to GET header to get the required html page, we have something called as HEAD header.
When you send a HEAD request for an URL we get a set of values for the URL
Example: if you want to know details of
<a href="https://www.wgz.org/chromatic/perl/IntroTestMore.pdf" target="_blank" rel="nofollow noopener noreferrer">PDF</a>
Send a head command to the URL
the response will be
Date: Mon, 03 Nov 2008 06:29:09 GMT
Accept-Ranges: bytes
ETag: "156046f-11889-3a578cd2bf2c0"
Server: Apache
Content-Length: 71817
Content-Type: application/pdf
Last-Modified: Thu, 11 Jul 2002 04:53:07 GMT
Client-Date: Mon, 03 Nov 2008 06:29:10 GMT
Client-Peer: 167.168.132.148:8080
Client-Response-Num: 1
Intresting Values:
Accept-Ranges, Content-Length
Accept-Ranges: bytes 'tells that server is ready to give files part by part as requested!'
If this doesn't appear then most probably the server will not allow resume download.
Content-Length:71817
This tells the size of the pdf file. Useful to find how much is still left to download while resuming. (infact from which byte we need to download.
2. Now since download manager knows that this server supports download by parts(resuming as well).
Explaining Steps done by Download manager(for only one split):
1. Connects to
<a href="https://www.wgz.org" target="_blank" rel="nofollow noopener noreferrer">WGZ Networks - Snafu</a> on port 80(where ever http is running) using a tcp connection.
2. Sends following text.
GET /chromatic/perl/IntroTestMore.pdf\n\n
3. The server starts sending some headers followed with file contents.
4. If you stop the download though the interface given the
- download manager disconnects the connectino
- prepares the temp file for the file downloaded (partly) and also keeps a track for how much got downloaded for example let it be 10000 bytes.
Resuming!:
Now when you click on resume download the download manager does:
Step 1. same as above
2. Sends the following text
GET /chromatic/perl/IntroTestMore.pdf\n
RANGE: bytes-unit = 10001\n\n
here bytes-unit specifies from which byte the files is required.
There are called range byte headers.
3. The server starts sending some headers followed with file contents(starting from 10001 byte instead of from beginning of file!).
4. Download manager starts appending the bytes recieved to previous temp
file.
5. Once total file is downloaded the DM changes the temp file to actual file name which could be used (file is now usable).
You can see http rfc for more details.
Now you could think how the splits work.
Actuall each download manager thread downloads part of file by specifying ranges and once everyone is done they join all the splits to give a complete file.
Thanks & Regards
Sriram