Original article from:
https://mp.weixin.qq.com/s/5Y8XD_T4F0U7SsDahc6nww

What is the HTTP

HTTP is Hyper Text Transfer Protocol, also known as Hyper Text Transfer Protocol, which is a convention and specification for the transmission of Text, pictures, audio, video and other hypertext data between two points in the computer world.

Let’s start with the HTTP name: Hypertext Transfer Protocol. As the name suggests, it can be split into three parts, respectively: hypertext, transport, protocol. So let’s talk about what each part means.

First of all, HTTP is a protocol, so what exactly is a protocol?

Actually “agreement” is not only limited in the computer world, the “agreement” is ubiquitous in real life, such as rent will sign a rental contract, graduate students will sign a tripartite agreement and the company will sign a confidentiality agreement, hires, and so on, deal penetrated into every aspect of life.

The reason why the “agreement” appears is also a kind of behavior agreement and norm for the participants. As the saying goes, “No rules, no place”, which also reflects the importance of agreements.

HTTP is a protocol used in the computer world. It establishes a protocol for communication between computers in a language that computers can understand, as well as the associated controls and error handling.

Now that’s the protocol, let’s move on to the second part of HTTP: transport

A transfer is A big push from point A to point B, or from point B to point A, “A<==>B”.

Take web surfing for example, Maimo browses the public number << Maimo coding>> on the mobile phone, and finds an article << HTTP is what the evil, popular >> to help them more, just click a “like”.

Take the operation of thumb up for example, the client needs to send the necessary data such as the ID of thumb up people and the ID of the article to the server, and the server will get these data to update the database. After the update is completed, the client will notify the existing thumb up number, and the client will update the thumb up number after getting the data sent by the server.

At this point, you have almost understood the second layer of HTTP.

Having said “protocol” and “transport”, we finally come to the third part of HTTP: hypertext

Since HTTP is a “transport protocol,” what exactly is the “hypertext” it transports? Why is it hypertext and not text? What is the difference between hypertext and text? Next, let’s talk slowly.

Let’s start with what the text is. Text indicates that HTTP transfers complete, meaningful data that can be processed by upper-level applications such as browsers and servers. It’s not the messy binary packets that are sliced up in some underlying protocol like TCP/UDP.

Hypertext is “text beyond ordinary text”. It is no longer limited to simple text, but a mixture of text, pictures, audio and video, etc. The most important thing is “hyperlink”, which can jump from one “hypertext” to another “hypertext”, forming complex nonlinear, networked organizational relations.

HTTP is a convention and specification for the transfer of text, images, audio, and video between two points in the computer world.

HTTP features

After the above talk about the meaning of HTTP, let’s take a look at why HTTP is so popular, he in the end what the devil, so that the Internet people can not extricate themselves.

I’ll give you a quick overview of the features of HTTP in one diagram, and then go into more detail. Think of the whole, then look at each feature.

– Simple and fast

When a client accesses a server, it simply passes the request method and path. Request methods commonly used are GET, HEAD, POST, and so on. Each method specifies the type of contact between the client and the server. Because HTTP protocol is simple, the program size of HTTP server is small, so the communication speed is very fast.

– Flexible and extensible

In the process of using HTTP data transmission, the request body is no longer limited to TXT or HTML in the form of text, but can transmit pictures, audio and video and other arbitrary data. You can also add some features to the request header, such as request method, version number, status code segment, and so on.

– Reliability transmission

HTTP is based on the TCP/IP protocol, and since TCP is a reliable transport protocol, HTTP naturally inherits this feature and can transfer data “reliably” between the requester and the responder.

However, it is important to understand the meaning of “reliable” correctly. HTTP is not a 100% guarantee that data will be sent to the other end, and it is possible to send and receive data in bad conditions such as a busy network or poor connection quality. “Reliable” simply provides a “promise” to users that they will “try their best” to ensure the complete delivery of data by various means at the lower level.

– a stateless

The HTTP protocol is a stateless protocol. Stateless, which means that the protocol has no memory for transactions. Stateless means that if the previous information is needed for subsequent processing, it must be retransmitted, which can result in an increase in the amount of data transmitted per connection. On the other hand, the server responds faster when it doesn’t need previous information.

We can compare the UDP protocol again, but it is connectionless and stateless, sequentially sent out of order to receive the packet, the packet sent out of order is ignored, after receiving it is not sorted in order. While HTTP is connected without state, the sequence of sending and receiving packets, according to the order of receiving and receiving messages management.

HTTP 1.0/1.1/2. X version

Http1.0 compare http1.1

– long connection

Processing Multiple HTTP requests and responses can be transmitted over a single TCP connection, reducing the cost and latency of establishing and closing the connection. Connection: keep-alive is enabled by default in HTTP1.1, which somewhat compensates for the fact that HTTP1.0 creates a Connection on every request.

– Request Pipelining

HTTP1.1 also allows the client request results back don’t have to wait for the last time, you can send out the next request, but the server must be in order to receive the order of the client request of echo response as a result, to ensure that the client can distinguish between the response content of each request, it also significantly reduce the time required to download the entire process.

Http1. X is http2. X

– Multiplexing mechanism

Http2.0 uses multiplexing to handle multiple requests concurrently on the same connection, and the number of concurrent requests is several orders of magnitude larger than in Http1.1. It is also possible to create several more TCP connections in HTTP1.1 to handle more concurrent requests, but there is an overhead associated with creating TCP connections.

– Header data compression

In HTTP1.1, HTTP requests and responses are made up of status lines, request/response headers, and message bodies. In general, the body of the message is GZIP compressed, or the message itself is a compressed binary, but the status line and header are transmitted as plain text without any compression. As Web functions become more and more complex, each page generates more and more requests, resulting in more and more traffic consumed in the head, especially every time to transmit content such as UserAgent, Cookie and so on, which will not change frequently, is a waste.

And the number of concurrent requests is several orders of magnitude larger than in HTTP1.1. It is also possible to create several more TCP connections in HTTP1.1 to handle more concurrent requests, but there is an overhead associated with creating TCP connections.

To this end, the request header can be slightly compressed, so that the request order can be done in one round, greatly saving time and resource waste.

– Use binary format

Binary is more efficient to parse than text protocols, more compact “on line”, and, most importantly, fewer errors.

– Server push

Server push is a mechanism for sending data before a client requests it. Web pages use many resources: HTML, stylesheets, scripts, images, and so on. Each of these resources must be explicitly requested in HTTP1.1. It’s a slow process. The browser starts by fetching HTML, then incrementally fetches more resources as it parses and evaluates the page. Because the server must wait for the browser to do every request, the network is often idle and underused.

To improve latency, Http2.0 introduces Server Push, which allows the server to push resources to the browser before the browser explicitly requests them, so that the client doesn’t have to create a connection again and send a request to the server to fetch it. This allows the client to load these resources directly from the local, rather than across the network.

That concludes the concepts, features, version differences, and features of HTTP, and that’s it for today.

See you next time ~~ ~

The article will also be updated continuously. You can search “Maimo coding” for WeChat to read it first time. Every day to share quality articles, Dachang experience, Dachang face, help interview, is a platform worth paying attention to every programmer.