Chunked encoding of HTTP

Source: Internet
Author: User

Generally, the HTTP header contains the Content-Length field to specify the length of the message style. For example:

Sometimes the service cannot determine the message size when generating an HTTP response, such as downloading a large file or using complicated logic in the background to process all page requests. In this case, the message length must be generated in real time, the server generally uses chunked encoding.

During chunked encoding transmission, the headers in the reply message have the transfer-coding Domain value chunked, indicating that the content will be transmitted using chunked encoding. Headers encoded with Chunked are as follows (you can use Firefox's firebug plug-in or httpwatch to view headers information, and httpwatch can also view the number of chunked ):

Chunked adopts the following encoding method:

Chunked-Body = * chunk
"0" CRLF
Footer
CRLF
Chunk = chunk-size [chunk-ext] CRLF
Chunk-datacrlf
Hex-no-zero = Chunk-size = hex-no-zero * hex
Chunk-ext = * (";" chunk-ext-name ["=" chunk-ext-value])
Chunk-ext-name = token
Chunk-ext-val = tokenquoted-string
Chunk-Data = chunk-size (octet)
Footer = * entity-Header

Encoding is composed of several chunks, ending with a chunk with a length of 0. Each chunk consists of two parts. The first part is the length and length unit of the chunk (generally not written ), the second part is the content with the specified length, and each part is separated by CRLF. In the last chunk with a length of 0, the content is called footer, which is a part of unwritten header content.

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.