Home >Common Problem >The difference between http1.0 and 1.1
1. HTTP 1.1 supports persistent connection (PersistentConnection) and request pipeline (Pipelining) processing
HTTP 1.0 stipulates that browsers and servers only Maintain a short-lived connection. Each request of the browser needs to establish a TCP connection with the server. The server immediately disconnects the TCP connection after completing the request processing. The server does not track each client nor record past requests. (Recommended learning: web front-end video tutorial)
HTTP 1.1 supports persistent connection, and uses persistent connection by default. Multiple HTTP requests and Response. Multiple requests and responses can overlap, and multiple requests and responses can be performed simultaneously. More request headers and response headers (for example, HTTP 1.0 does not have a host field).
In 1.0 Session mode:
1. Establish a connection
2. Send a request message
3. Send back a response message
4. Close the connection
HTTP 1.1's continuous connection also needs to add new request headers to help implement it. For example, when the value of the Connection request header is Keep-Alive, the client notifies the server to maintain the connection after returning the result of this request; Connection When the value of the request header is close, the client notifies the server to close the connection after returning the result of this request. HTTP 1.1 also provides request headers and response headers related to mechanisms such as authentication, state management, and Cache caching.
Pipelining processing of requests can transmit multiple HTTP requests and responses on a TCP connection, reducing the consumption and delay of establishing and closing connections. For example, multiple requests and responses for a web page file containing many images can be transmitted over a single connection, but the requests and responses for each individual web page file still need to use their own connections. HTTP 1.1 also allows the client to make the next request without waiting for the result of the previous request to be returned. However, the server must send back the response results in the order in which the client request is received to ensure that the client can distinguish the content of each request. Response content.
2.HTTP 1.1 adds host field
In HTTP1.0, it is considered that each server is bound to a unique IP address, therefore, the URL in the request message The hostname is not passed. However, with the development of virtual host technology, multiple virtual hosts (Multi-homed Web Servers) can exist on a physical server, and they share an IP address.
HTTP1.1 request messages and response messages should support the Host header field, and if there is no Host header field in the request message, an error (400 Bad Request) will be reported. Additionally, the server SHOULD accept resource requests marked with absolute paths.
3. 100 (Continue) Status (save bandwidth)
HTTP/1.1 has added a new status code 100 (Continue). The client sends a request with only the header field in advance. If the server rejects the request due to permissions, it will send back the response code 401 (Unauthorized); if the server receives the request, it will send back the response code 100, and the client can continue to send the complete request with the entity. . The use of the 100 (Continue) status code allows the client to use the request header to test the server before sending the request message body to see if the server wants to receive the request body, and then decide whether to send the request body.
4. Chunked transfer-coding was introduced in HTTP/1.1 to solve the above problem. The sender divides the message into several data blocks of any size, and each data block will be attached with the block when sending. length, and finally use a zero-length block as a sign of the end of the message. This approach allows the sender to buffer only a fragment of the message, avoiding the overload caused by buffering the entire message.
5. HTTP/1.1 adds some new cache features on the basis of 1.0. When the Age of the cached object exceeds Expire, it becomes a stale object. The cache does not need to discard the stale object directly, but communicates with the source server. Perform revalidation.
The above is the detailed content of The difference between http1.0 and 1.1. For more information, please follow other related articles on the PHP Chinese website!