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.