HTTP keep-alive Explanation

Source: Internet
Author: User
Tags keep alive

1. Concept

Keep-alive mode (also known as persistent connection, connection reuse), the Keep-alive feature keeps the client-to-server connection active, and keep-alive functionality avoids establishing or re-establishing a connection when a subsequent request to the server occurs.

HTTP 1.0 is turned off by default, you need to add "connection:keep-alive" in the HTTP header to enable keep-alive,keep-alive is enabled by default in HTTP 1.1, if you join "Connection: Close "before it is closed . Most browsers now use the http1.1 protocol, which means that the Keep-alive connection request is initiated by default, so whether a full keep-alive connection can be completed depends on the server setup.

2. How to determine the connection interruption

Description

In HTTP 1.0 and previous versions, the Content-length field is optional.
In http1.1 and later versions. If it is keep alive, then content-length and chunk must be two to choose one . If the non-keep alive, then the same as http1.0. Content-length is dispensable. If you have a transfer-encoding, you cannot have content-length.

(1) Content-length

Content-LengthRepresents the length of the entity content . The browser uses this field to determine whether the currently requested data has been fully received .
Therefore, when a browser requests a static resource, that is, the server can explicitly know the length of the returned content, it can be set Content-Length to control the end of the request. However, when the server does not know the length of the request result, such as a dynamic page or data, can Content-Length not solve the above problem, this time need to use the Transfer-Encoding field.

(2) transfer-encoding

The chunk code divides the data into a piece of the occurrence. The chunked encoding will be concatenated with a number of chunk, ending with a chunk marked with a length of 0 .

HTTP keep-alive Explanation

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.