Chunked encoding in HTTP (transfer-encoding:chunked)

Source: Internet
Author: User

  Turn from: wonderful day girl--chunked transmission Code ~

Reference Links:

    1. HTTP Mdn--http Protocol

First, background:

    1. Persistent connection problem: for a non-persistent connection, the browser can define the boundary of the request or response entity by whether the connection is closed or not, and for persistent connections, this method is obviously ineffective. Sometimes, although I have sent all the data, but the browser does not know this, it can not tell whether the open connection will still have new data come in, can only be silly to wait.
    2. Solved with Content-length: Calculates the length of the body and tells the other through the head. The browser can determine the end of the response entity by content-length the length information
    3. New issues introduced by Content-length: Because the Content-length field must truly reflect the length of the entity, for dynamically generated content, the length is not known until the content is created. At this time to accurately obtain the length, can only open a large enough buffer, and so on all the content generated good recalculation. But doing so requires a lot more memory overhead and, on the other hand, makes the client wait longer.
    4. We need a new mechanism: not depending on the length of the header, but also the boundaries of the entity--chunked coding (transfer-encoding:chunked)

Two, Block code (transfer-encoding:chunked)

      1. Transfer-encoding, is an HTTP header field (response Header field), which literally means "transmission encoding". In the latest HTTP specification, only one encoding transmission is defined: chunked encoding (chunked).
      2. chunked transfer encoding (Chunked transfer encoding) is a data transfer mechanism in Hypertext Transfer Protocol (HTTP) that allows HTTP data sent by the Web server to the client to be divided into multiple parts. chunked transfer encoding is only available in the HTTP Protocol version 1.1 (http/1.1).
      3. The data is decomposed into a series of chunks and sent in one or more blocks, so that the server can send data without needing to know the total size of the sent content beforehand.
      4. Specific methods
        1. After adding transfer-encoding:chunked to the head, the message is represented by a chunked code. At this point, the entity in the message needs to be transferred by a series of blocks.
        2. Each tile contains 16 binary length values and data, the length value is exclusive to one row, the length does not include the CRLF at its end (\ r \ n), or the CRLF at the end of the chunked data.
        3. The last chunk length value must be 0, the corresponding chunked data has no content, indicating the end of the entity.
      5. Cases:

      6. Content-encoding and transfer-encoding are often combined to use, in fact, the transfer-encoding for the sub-block and then content-encoding compression.

Chunked encoding in HTTP (transfer-encoding:chunked)

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.