HTTP Protocol Overview and Core Features

HTTP (Hypertext Transfer Protocol, HyperText Transfer Protocol) is a protocol used for communication on the Web. It is a stateless protocol, meaning that each request and response are independent, and the server does not retain any state information between different requests.
The HTTP protocol uses a client-server model, in which the client initiates a request and the server returns a response. Communication between the client and the server is implemented through the format of request and response messages, which consist of a start line, headers, and a body.
Common methods used by the HTTP protocol include GET, POST, PUT, DELETE, etc. The GET method is used to retrieve resources from the server, the POST method is used to submit data to the server, the PUT method is used to upload files to the server, and the DELETE method is used to delete resources from the server.
The HTTP protocol uses URLs (Uniform Resource Locators) to specify the resources to be accessed. A URL includes parts such as the protocol, hostname, port number, path, and query parameters.
The HTTP protocol also supports mechanisms such as cookies and sessions to handle state information, and uses SSL/TLS encryption protocols to ensure the security of communication.

Lifecycle

The lifecycle of the HTTP protocol can be divided into the following stages:

  1. Establish Connection: The client initiates a request to the server. The request includes information such as the target server's IP address, port number, HTTP method, and URL. Upon receiving the request, the server establishes a TCP connection and then waits for the client to send the request content.
  2. Send Request: Through the established TCP connection, the client sends a request message to the server. The request message consists of two parts: the request header and the request body. The request header contains information such as the request method, target URL, protocol version, and request header fields, while the request body contains the data carried by the request.
  3. Process Request: Upon receiving the request, the server parses the request header and the request body. Based on the request header information and URL information, it determines the operation to be executed, such as querying a database or reading a file from the file system.
  4. Send Response: After processing the request, the server sends a response message to the client. The response message consists of two parts: the response header and the response body. The response header contains information such as the response status code, protocol version, and response header fields, while the response body contains the data carried by the response.
  5. Close Connection: Once the server finishes sending the response message, or if an error occurs when the client receives the response message, the connection is closed, and the TCP connection is also closed.

Throughout this process, the HTTP protocol maintains its stateless nature, meaning that each request and response are independent, and the server does not retain any state information between different requests. If state information needs to be maintained, mechanisms such as cookies and sessions can be used.

Version Differences

HTTP (Hypertext Transfer Protocol) is a protocol used for transmitting data on the Web. HTTP has multiple versions, with the most commonly used being HTTP/1.1 and HTTP/2, along with HTTP/1.0 and HTTP/0.9.

Below are the main differences between HTTP versions:

  1. HTTP/0.9: The earliest version of HTTP, capable of transmitting only plain text HTML files. It does not support HTTP header information or status codes, nor does it support features like SSL encryption.
  2. HTTP/1.0: Introduced HTTP header information and status codes, supporting the transmission of various file formats. However, each request requires establishing a new TCP connection, resulting in lower efficiency.
  3. HTTP/1.1: Introduced technologies such as persistent connections and pipelined transmission, allowing multiple requests and responses to be transmitted over a single TCP connection, thereby improving efficiency. It also supports chunked transfer encoding, HTTP caching, and other features.
  4. HTTP/2: Developed based on Google's SPDY protocol, it uses binary format for data transmission, supports multiplexing, and allows multiple requests and responses to be transmitted simultaneously over a single TCP connection, reducing latency. It also supports header compression, server push, and other features.