How do Pause-able downloads work?

I use Internet Download Manager (IDM) for downloading data, and I have noticed that in it's download progress window, it shows whether or not a download is pause-able (resume-able). Typically, file-sharing sites do not allow the transfer to be resumed if the connection is broken.

So the question is this: how does this work? Is it some config that's done on the sever? How does this differ from torrent downloads, where the download is always resume-able.


Solution 1:

From a coding perspective, a download is just a just a byte array included in the HTTP response stream.

The HTTP 1.1 protocol (see page 30) includes a field in the Header called 'Range', which allows the request to specify the byte offset and length of the response requested.

So in essence you can say, "give me the HTTP object at this URL, but I only want the 1024th - 4096th bytes of it". The client browser then appends the byte stream to the portion of the file already downloaded. The client can tell where it needs to resume simply by checking the length of the file already downloaded, and increments it to determine the required offset.

As to how your download manager can tell, it sends an HTTP "HEAD" request. If the response code is 206 (partial content), then the http stream supports resumption.

Solution 2:

This could be handled using a Persistent cookie, not to be confused with a session cookie or you can use [Viewstate] if the site is built on ASP.NET, however this is not a good practice. Frank Thomas has the best answer.