HTTP can transmit data in a direct way, but it can also increase the transmission rate by encoding during transmission. By encoding during transmission, a large number of access requests can be handled efficiently. However, the encoded operation requires the computer to complete, thus consuming more resources such as CPU.
The difference between the message body and the entity body
message : is the basic unit of HTTP communication, consisting of 8-bit byte streams, which are transmitted over HTTP traffic.
entity : The payload data is transmitted as a request or response, and its contents consist of the entity header and the entity body .
The body of an HTTP message is used to transfer the entity body of the request or response. Typically, the message body equals the entity body . The content of the entity body is changed only when it is encoded in the transmission, which causes it to differ from the message body.
Content encoding for compressed transmissions
When adding attachments to outgoing messages, in order to make the message smaller, we will compress the files before adding attachments. There is a feature called content encoding in the HTTP protocol that can perform similar operations. content Encoding indicates the encoding format applied on the entity content and keeps the entity information compressed as it is, and the content-encoded entity is received by the client and is responsible for decoding .
commonly used content encoding has the following types :
chunked transfer encoding for split sending
In the HTTP communication process, the requested encoding entity resource has not been fully transferred until the browser cannot display the request page. when transferring large volumes of data, by splitting the data into chunks, the browser is able to display the page progressively. This function, which blocks the entity body, is called chunked transmission encoding (Chunked Transfer Coding).
chunked Transfer Encoding divides the entity body into multiple parts ( blocks ). Each block is marked with hexadecimal, and the last piece of the entity body is marked with "0 (CR+LF)" . Entity principals that use chunked transfer encoding are decoded by the receiving client and revert to the entity body before the encoding. There is a mechanism called transfer encoding (Transfer Coding) in http/1.1 , which can be transmitted in a coded manner during communication, but only defined in the chunked transfer encoding .
Encoding of HTTP messages within HTTP messages increases transfer rate