The HTTP protocol uses the request/response model. The client sends a request message to the server, and the server responds with a state.
The following are the steps for HTTP request/Response:
The client connects to the Web server: The HTTP client establishes a TCP connection with the Web server;
The client initiates an HTTP request to the server: the client sends a request message to the server through an established TCP connection;
The server receives an HTTP request and returns an HTTP response: The server resolves the request, locates the request resource, and the server writes the resource copy to the TCP connection, which is read by the client;
Release TCP connection: If the connection mode is close, the server actively shuts down the TCP connection, the client shuts down the connection passively, releases the TCP connection, and if connection mode is keepalive, the connection remains for a period of time and can continue to receive requests ;
The client browser parses the HTML content: the client parses and displays the HTML text of the server response;
For example: Type the URL in the browser address bar and press ENTER to experience the following process:
1. The browser requests the DNS server to resolve the IP address of the domain name in the URL;
2, after resolving the IP address, according to the IP address and the default port 80, and the server to establish a TCP connection;
3, the browser issued a read file (the URL in the back part of the corresponding file) HTTP request, the request message as a TCP three handshake third message data sent to the server;
4, the server responds to the browser request, and the corresponding HTML resulting sent to the browser;
5, release the TCP connection;
6, the browser will be the HTML text and display content;
HTTP Stateless
The HTTP protocol is stateless (stateless). That is, when the same client accesses a page on the same server for the second time, the server cannot know that the client has visited and the server cannot distinguish between different clients. The stateless nature of HTTP simplifies the design of servers, making it easier for servers to support a large number of concurrent HTTP requests.
HTTP Persistent Connection
HTTP1.0 uses a non-persistent connection, the main drawback is that the client must establish and maintain a new connection for each object to be requested, that is, twice times the cost of the RTT per request for a document. Because there may be multiple objects on the same page, non-persistent connections can make a page download very slow, and this short connection increases the burden of network transmission. HTTP1.1 uses persistent connection keepalive, the so-called persistent connection, that is, the server after sending the response still for a period of time to maintain the connection, allowing multiple data requests and responses in the same connection, that is, in the case of persistent connection, the server does not close the TCP connection after sending the response, The client can continue to request other objects through this connection.
There are two ways to http/1.1 a persistent connection to a protocol:
Non-pipelined mode: The customer receives the previous response before issuing the next request;
Pipelining: The customer can then send a new request message before receiving the HTTP response message;
How HTTP Works