The principle of implementing breakpoint resume in Linux

  
                

The resume of the breakpoint is very common now. If there is no breakpoint, then the downloaded content has been downloaded 90%, but the download process is interrupted, so download it from the beginning. This article will briefly introduce how the Linux system breakpoint resume is implemented.

HTTP principle

In fact, HTTP principle is very simple, that is the Http requests and generally download was different.

For example, when a browser requests a message on the server, the request is as follows:

Suppose the server domain name is wwwws.sjtu.edu.cn and the file name is down.zip .

GET /down.zip HTTP/1.1

Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-

excel, application/msword, application/vnd.ms-powerpoint, */*

Accept-Language: zh-cn

Accept-Encoding: gzip, deflate

User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)

Connection: Keep-Alive

After receiving the request, the server looks for the requested file and extracts the file as required. The information is then returned to the browser, and the returned information is as follows:

200

Content-Length=106786028

Accept-Ranges=bytes

Date= Mon, 30 Apr 2001 12:56:11 GMT

ETag=W/“02ca57e173c11:95b”

Content-Type=application/octet-stream

Server= Microsoft-IIS/5.0

Last-Modified=Mon, 30 Apr 2001 12:56:11 GMT

The so-called breakpoint resume, that is, to start from where the file has been downloaded Download. So add a message when the client browser passes to the web server -- where to start.

The following is to use a "browser" that you have compiled to pass the request information to the Web server, starting with 2000070 bytes.

GET /down.zip HTTP/1.0

User-Agent: NetFox

RANGE: bytes=2000070-

Accept: text/html, image /gif, image/jpeg, *; q=.2, */*; q=.2

A closer look reveals a line RANGE: bytes=2000070-

The meaning of one line is to tell the server that the file down.zip starts from 2000070 bytes, and the preceding bytes are not passed.

After receiving this request, the server returns the following information:

206

Content-Length=106786028

Content-Range=bytes 2000070-106786027 /106786028

Date=Mon, 30 Apr 2001 12:55:20 GMT

ETag=W/“02ca57e173c11:95b”

Content-Type=application/octet -stream

Server=Microsoft-IIS/5.0

Last-Modified=Mon, 30 Apr 2001 12:55:20 GMT

Compare with the information returned by the previous server , you will find a line added:

Content-Range=bytes 2000070-106786027/106786028

The returned code is also changed to 206, instead of 200.

Knowing the above principle, you can program the breakpoint. Previous12Next page Total 2 pages

Copyright © Windows knowledge All Rights Reserved