1.HTTP is used for communication between clients and servers
2. Communicate by exchanging requests and responses
Request message: request method, request URI, protocol version, optional request header field, and content entity.
Response message: consists of the protocol version, status code, status code cause phrase, optional response header field, and entity body.
3.HTTP is a protocol that does not save state
HTTP is a stateless protocol that does not save state. The HTTP protocol itself does not store the communication status between the request and response, and does not persist. Cookie technology was introduced to achieve the desired stateful functionality. Manage state.
4. Request the URI to locate the resource
The HTTP protocol uses URIs to locate resources on the Internet. Because of the specific functionality of URIs, resources can be accessed anywhere on the Internet.
5. HTTP methods that tell the server the intent
- GET: Obtains resources
- POST: Transmits the body of the entity
- PUT: transfers files
- HEAD: obtains the packet HEAD
- DELETE: deletes a file
- OPTIONS: Asks for supported methods
- TRACE: indicates a tracing path
- CONNECT: The tunnel protocol is required to CONNECT to the agent
6. Use the command
When a request message is sent to a resource specified by the request URI, a command called a method is used.
7. Persistent connections save traffic
In the initial VERSION of HTTP, TCP connections are disconnected for each HTTP communication, which increases the communication overhead. When you send a request to access a resource on an HTML page that contains multiple images, you will also request other resources contained in the HTML page. Each request causes unnecessary TCP connections to be established or disconnected, increasing the traffic overhead.
7.1 Persistent Connection
To solve the problem of TCP Connections, HTTP/1.1 and some HTTP/1.0 introduced HTTP Persistent Connections (also known as HTTP keep-alive or HTTP).
Feature: As long as neither end explicitly disconnects, the TCP connection remains in the state. Benefits: Reduces the overhead caused by the repeated establishment and disconnection of TCP connections, reducing the load on the server side. In HTTP/1.1, all connections are persistent by default.
7.2 pipelines
Persistent connections make it possible to pipe most requests. Multiple requests can be sent in parallel without having to wait for one response after another.
8. Use cookies for state management
The Cookie notifies the client to save the Cookie according to the set-cookie header field in the response packet sent from the server. When the client sends a request to the server next time, the client automatically adds the Cookie value to the request packet and sends the request packet. The server compares the record on the server according to the cookie sent by the client, and finally obtains the previous state information.
- Request message (state without Cookie information);
- Response message (Cookie information generated by the server);
- Request message (automatically sends saved Cookie information).
Request in the state without Cookie information
Request after the second time (with Cookie information state)