HTTP/1.1 range and content-Range

Source: Internet
Author: User

HTTP/1.1 range and content-range (Note: reprinted on http://www.91linux.com/html/article/program/cpp/20090411/16420.html)

 

Suppose you want to develop a multi-thread download tool, you will naturally think of splitting the file into multiple parts, such as four parts, and then create four threads, each thread is responsible for downloading one part, if the file size is 403 bytes, you can split it into 0-99 (first 100 bytes), 100-199 (second 100 bytes ), 200-299 (third 100 bytes), 300-402 (last 103 bytes ).

after splitting, each thread understands its own job. For example, the job in thread 3 is responsible for downloading the file-. The problem is: what kind of request message is sent by thread 3 to ensure that only the-299 bytes of the request file will not interfere with the tasks of other threads. In this case, we can use the range header of http1.1. The range header field can request one or more sub-ranges of an object. A value of 0 indicates the first byte, that is, the number of bytes calculated by range starts from 0:
indicates the first 500 Bytes: range: bytes = 0-499
indicates the second 500 Bytes: range: bytes = 500-999
indicates the last 500 Bytes: range: bytes =-500
indicates the range after 500 Bytes: range: bytes = 500-
first and last Bytes: range: bytes = 0-0, -1
specify the following ranges: range: bytes = 500-600,601-999
therefore, the request message sent by thread 3 must have this line:
range: bytes = 200-299

The server receives the request message from thread 3 and finds that this is a GET request with a range header. If everything is normal, the server's response message will have the following line:
HTTP/1.1 206 OK
Indicates that the request is successfully processed, and the response message contains this line.
Content-range: bytes 200-299/403
The value 403 after the slash indicates the file size. The common usage of content-range is as follows:
. The first 500 Bytes:
Content-range: BYtes 0-499/1234

. The second 500 Bytes:
Content-range: bytes 500-999/1234

. All bytes t for the first 500 Bytes:
Content-range: bytes 500-1233/1234

. the last 500 Bytes:
content-range: bytes 734-1233/1234

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.