HTTP Lecture 11 - Features of HTTP

insert image description here

flexible and scalable

First of all, the HTTP protocol is a "flexible and extensible" transport protocol.
The HTTP protocol was relatively simple when it was first born. In the spirit of openness, it only stipulated the basic format of the message, such as separating words with spaces, separating fields with newlines, "header+body", etc. There are no strict syntax and semantic restrictions, and can be customized by developers.
The HTTP protocol has grown up with the development of the Internet. During this process, the HTTP protocol gradually adds features such as request method, version number, status code, and header field. The body is no longer limited to TXT or HTML in the form of text, but can transmit arbitrary data such as pictures, audio and video, all of which are due to its "flexible and scalable" characteristics
.

reliable transmission

The second feature, the HTTP protocol is a "reliable" transport protocol.
Because the HTTP protocol is based on TCP/IP, and TCP itself is a "reliable" transmission protocol, HTTP naturally inherits this feature and can "reliably" transmit data between the requester and the responder.
Its specific method is similar to that of TCP/UDP. It packs the actual transmitted data (entity), adds a header, and then calls the Socket API to send or receive through the TCP/IP protocol stack.
However, we must correctly understand the meaning of "reliable". HTTP does not guarantee 100% that data can be sent to the other end. In harsh environments such as busy networks and poor connection quality, sending and receiving may fail. "Reliable" just provides a "commitment" to the user, and the lower layer will use various means to "try" to ensure the complete delivery of data.
Of course, in the extreme situation where the optical fiber is accidentally cut, even a god cannot send it successfully. Therefore, "reliable" transmission means that data transmission and reception must be successful when the network is basically normal.

application layer protocol

The third feature is that the HTTP protocol is an application layer protocol.
In the decades after the birth of TCP/IP, although many application layer protocols have emerged, they only focus on small application fields and are limited to few application scenarios. For example, FTP can only transfer files, SMTP can only send emails, and SSH can only log in remotely, etc., and "cannot type at all" in terms of general data transmission.
Therefore, HTTP relies on the message structure that can carry arbitrary header fields and entity data, as well as convenient and easy-to-use features such as connection control and caching proxy. Once it appears, it "overwhelms the crowd" and quickly becomes the "star" protocol in the application layer. . As long as performance is not too demanding, HTTP can deliver almost everything and meet various needs, so it can be called a "universal" protocol.

request-response

The fourth characteristic is that the HTTP protocol uses a request-response communication mode.
This request-response mode is the most fundamental communication model of the HTTP protocol. Generally speaking, it is "one send and one receive" and "come and go". It is like a function call when writing code. Just fill in the fields in the request header, "Call" and you'll get a reply.
The request-response mode also clarifies the positioning of the two parties in the HTTP protocol. The requester always initiates the connection and request first, which is active, while the responder can only reply after receiving the request, which is passive. If there is no request, it will not There will be no action.
Of course, the roles of the requester and the responder are not absolute. In the browser-server scenario, the server is usually the responder, but if it is used as a proxy to connect to the backend server, it may also act as the requester. and the role of the respondent.
The request-response mode of HTTP also fits the traditional C/S (Client/Server) system architecture, where the requester acts as the client and the responder acts as the server. Therefore, with the development of the Internet, the B/S (Browser/Server)
architecture , using lightweight browsers instead of heavy client applications to achieve zero-maintenance "thin" clients, while the server abandoned private The communication protocol is changed to HTTP protocol.

no status

The fifth feature, the HTTP protocol is stateless.
"Status" is actually some data or signs saved in the client or server, which records some change information during the communication process.
You must know that the TCP protocol is stateful. It is in the CLOSED state at the beginning, the ESTABLISHED state after the connection is successful, the FIN-WAIT state after the disconnection, and finally the CLOSED state.
These "states" need to be maintained by TCP with some internal data structures, which can be simply imagined as a flag to mark the current state, for example, 0 is CLOSED, 2 is ESTABLISHED and so on.
Let’s look at HTTP again, then compare TCP to see that there is no “state” specified in the entire protocol, and the client and server are always in a state of “ignorance”. Before the connection is established, the two do not know each other, and the messages sent and received each time are also independent of each other without any connection. Sending and receiving messages will not have any impact on the client or server, and will not ask to save any information after connecting.

"Stateless" is figuratively speaking, "no memory ability". For example, the browser sends a request saying "I am Xiaoming, please give me file A." After receiving the message, the server will check the permissions, see that Xiaoming can indeed access file A, and then send the file back to the browser device. Then the browser still wants the B file, but the server will not record the status of the previous request. It does not know that the second request and the first request are sent by the same browser, so the browser must repeat its identity Caixing: "I am Xiao Ming just now, please give me file B again."
We can compare the UDP protocol again, but it is connectionless and stateless. Packets are sent in order and received out of order. Yes, it will not be arranged in order after receipt. HTTP, on the other hand, has connections and is stateless. Packets are sent and received sequentially, and packets are managed in the order they are sent and received.

other features

In addition to the above five major features, the HTTP protocol can actually list a lot of features, such as caching and compressing the transmitted entity data, obtaining data in segments, supporting identity authentication, and supporting international languages. But these are not the basic features of HTTP, because they are all derived from the first "flexible and scalable" feature.

summary

  1. HTTP is flexible and extensible, and header fields can be added arbitrarily to achieve any function;
  2. HTTP is a reliable transmission protocol, based on the TCP/IP protocol "as far as possible" to ensure the delivery of data;
  3. HTTP is an application layer protocol, which has more general functions than FTP, SSH, etc., and can transmit arbitrary data;
  4. HTTP uses the request-response mode, the client actively initiates the request, and the server passively replies to the request;
  5. HTTP is stateless in nature, each request is independent and unrelated to each other, and the protocol does not require the client or server to record request-related information.

PS: This article is a note after watching Geek.

Supongo que te gusta

Origin blog.csdn.net/Elon15/article/details/130679717
Recomendado
Clasificación