Chapter 2 simple HTTP protocol
The HTTP protocol states that the communication starts with the client and the server does not send a response until the request is received.
A request message consists of the request method, request URI, protocol version, optional request header fields, and content entities.
The response message basically consists of the protocol version, the status code, the reason phrase used to explain the status code, the optional response header field, and the entity body.
HTTP is a stateless protocol that does not save state.
The HTTP protocol itself does not store the state of communication between requests and responses. That is, at the HTTP level, the protocol does not persist requests or responses that have been sent.
Although HTTP/1.1 is a stateless protocol, Cookie technology was introduced in order to achieve the desired state retention function. With cookies and HTTP communication, you can manage state
HTTP method to inform the server of the intent
-
GET: Obtains resources
-
POST: transmits the entity body
-
PUT: transfers files
-
HEAD: obtains the packet header, which is used to confirm the validity of the URI and the date and time of resource update
-
DELETE: deletes a file
-
OPTIONS: Ask for supported methods (Allow: GET, POST, HEAD, OPTIONS)
-
TRACE: Traces the path. The TRACE method is used to loop back the previous request traffic to the client. At the time of sending the request, the forward field of max-forwards is filled with a value. After passing through each end, the value is reduced by one. When the value reaches zero, the transmission is stopped.
-
CONNECT: The tunnel protocol is used to CONNECT the proxy. Secure Sockets Layer (SSL) and Transport Layer Security (TLS) are used to encrypt the communication content and transmit it through the network tunnel
Persistent connections save traffic
In the original version of the HTTP protocol, TCP was disconnected for every HTTP communication
In the case of communications in those days, it was all very small text transfers, so even this was not a problem. However, with the popularity of HTTP, it has become more common for documents to contain large numbers of images.
For example, when viewing an HTML page with multiple images in a browser, it sends a request to access the resources of the HTML page and also asks for other resources contained in the HTML page. Therefore, each request causes unnecessary TCP connection establishment and disconnection, increasing the traffic overhead.
A persistent connection
To solve the above TCP connection problem, HTTP/1.1 and some HTTP/1.0 came up with HTTP Persistent Connections. Also known as HTTP keep-alive or HTTP Connection reuse). The characteristic of a persistent connection is that the TCP connection remains as long as neither end explicitly disconnects.
pipelines
Persistent connections make it possible to send most requests as pipelining. After sending the previous request, wait and receive the response before sending the next request. With the advent of pipelining, the next request can be sent directly without waiting for a response
State management using cookies
HTTP is a stateless protocol that does not manage the status of previous requests and responses. That is, the request cannot be processed based on the previous state.
While preserving the feature of stateless protocol, Cookie technology is introduced to solve similar contradictory problems. Cookie technology controls the state of the client by writing Cookie information in the sum request response message.
The Cookie notifies the client to save the Cookie based on 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
After discovering the Cookie sent by the client, the server will check which client sent the connection request, and then compare the records on the server to obtain the previous status information