Content-length and Transfer-encoding in the HTTP protocol response header

Source: Internet
Author: User

Source:

http://blog.csdn.net/superhosts/article/details/8737434

http://bbs.csdn.net/topics/390384017

There are two main ways to verify the length of the content that the request for HTTP returns results:

1. When the client is in the HTTP header (head) plus connection:keep-alive, the server's response is the form of transfer-encoding:chunked, notifying the page that the data has been received. For example, a long connection or a program can be dynamically output content, for example, some operations are complex and require the user to get the latest results in a timely manner, then use chunked encoding content chunked output.

2. Except as described in 1, it is generally possible to obtain content-length.

Content-length If it exists and is valid, it must be exactly the same as the transmission length of the message content . (After testing, if it is too short, it is truncated and too long results in a timeout.) )

If there is a transfer-encoding (with emphasis on chunked), there can be no content-length in the header, and there will be neglect.

-----------------------------------------------------------------------------------------------------

Transfer-encoding:chunked means: While reading the data, it is sent to the client side. Not a second transmission. will take this header message.
Content-length: That is, the server has been cached in which to say, the message sent to the client will take this header information.

This is the case, the server is dynamically generated, you when the data is very small, not exceeding the buffer size of the servers
The header of HTTP has not been transmitted and can transmit the content-length.
In cases where the size of the data exceeds buffer, the server must flush the HTTP header and entity (data) to the client, at which point the entity size is still unknown, so there is no content-length.

Content-length and Transfer-encoding in the HTTP protocol response header

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.