【 introduction 】

With the attitude that the best way to learn is to teach others to learn, write down some of what you’ve learned. If there are any mistakes in this article, please point them out in the comments section.

What is HTTP?

HTTP is a hypertext transfer protocol. It is a request-response protocol. It transmits data based on TCP/IP communication protocol. It is part of the TCP/IP application layer. HTTP has gone through a number of versions since its release, and each version has been updated quite a bit. Here are some of the differences.

The HTTP 0.9

It is the most traditional request-response mode, extremely simple, and only supports GET methods to send requests, with no support for headers.

The HTTP 1.0

HTTP1.0 specifies that the browser and server can only maintain a transient connection, each time a request is sent to the server to establish a TCP connection, the server will immediately disconnect TCP after processing (no connection), and the server does not track the client and does not record past requests (stateless).

change

  1. HTTP1.0 can be considered an extended version of HTTP0.9, which adds HTTP version numbers, version management capabilities, and is also a sign of its beginning to engineering
  2. HTTP now supports headers, both req and RES.
  3. The status code is added, so that the requestor and the corresponding party have a unified understanding of the management program, can clearly know what is wrong, so that the control error and business error separation, improve work efficiency.
  4. With content-Type, you can transfer files in multiple formats.

disadvantages

  1. Unable to reuse:

Because HTTP1.0 is a connectionless protocol, TCP connections are disconnected each time the server processes a request. So each time a client requests a resource, it creates a new TCP connection, and it makes a serial request. TCP connections use three-way handshakes to maintain data reliability. This operation is expensive, so network utilization is low. Even if you have a fast network, web pages are slow to open.

  1. Team head congestion

HTTP1.0 states that the next request initiated by the client cannot be sent until the previous request arrives. If the previous request response does not arrive, the next request will not be sent, causing congestion.

HTTP1.1

HTTP1.1 is a huge optimization for network performance issues

change

  1. Long connection:

Keep-alive allows HTTP to reuse TCP connections by setting the Connection field in HTTP1.1, saving the overhead associated with the three-way handshake. Set Connection to false when you don’t want to reuse TCP.

Since the connection field was added to 1.1, it has been possible to make long connections by introducing the field to 1.0, but by default they are turned off, as they were in 1.1.

  1. pipelines

In HTTP1.0, the next request must be sent when the previous one arrives. In HTTP1.1, instead of waiting for the first request to come back, the second request can be sent directly, reducing the response time. In fact, multiple Http requests are sent in a SINGLE TCP connection without waiting for the server to respond to the previous request. The “parallel” sending of requests is implemented. But it’s not really parallel.

Because the server must return the results of the response in the order requested by the client, to ensure that the client can distinguish the contents of the response from each request. This is equivalent to moving the first-in, first-out queue from the client to the server. It doesn’t allow two parallel responses, so it doesn’t really solve head blocking, and many browsers don’t support it.

  1. Added a cache

In contrast to the strong Expires cache flag used in HTTP1.0, cache-control was added. The GMT time used in Expires is limited by the client’s time, whereas cache-control uses max-age to set the lifetime of the cache, relative to the client’s value. Not an absolute value like Expires.

ETag, if-none-match and other negotiation cache flags are also added, which will not be explained here.

  1. The HOST field

When the HOST field is added, the server can get the domain name information from HTTP, rather than the IP information translated by DNS, so multiple domain names can be resolved to the same server, allowing the server to create multiple sites.

  1. Increased security, support for a variety of network protocols

HTTP2.0

Although HTTP1.1 has been optimized in many ways, it still has performance issues. For example, sending requests is still sequential and cannot be truly parallel. And HTTP1.1 transmission to text using ZIP compression to send, transmission costs. So HTTP2.0 came along.

change

1. Binary frame division

Http2.0 is a binary protocol. Compared to the text transmission of HTTP1.1, it uses the binary format for transmission. It cuts the request and response into smaller frames and uses the binary encoding for more efficient parsing.

  1. multiplexing

HTTP2.0 implements true parallel transport, which can carry out any number of HTTP requests over a TCP connection, based on the binary framing feature

  • The data stream is sent as a message, consisting of one or more frames that can be sent out of order and then reassembled according to the stream identifier
  • All communication under the same domain name is completed in a single connection, requiring only one TCP connection, eliminating the delay and memory consumption caused by multiple TCP connections.
  1. Server push

The server can actively push other resources while sending HTML, rather than waiting for the browser to parse to the response location (following the same origin, and if the resource has been cached, can also reject).

For example, it actively pushes other resources when sending HTML.

  1. The head of compression

In 2.0, encoder is used to reduce the size of the transmission header. Both sides will have a header fields table for each cache to avoid repeated transmission, and the header is compressed by algorithm.

disadvantages

Because multiple HTTP requests reuse a TCP connection, TCP does not know how many upper-layer HTTP requests there are. Once packet loss occurs, all requests have to wait for the lost packet to return.

Http1.x differs from HTTP2.0

  1. Http1.x is text-based, while 2.0 is binary and faster
  2. Http1.x must get the response in the order requested, whereas 2.0 can be out of order and is truly parallel
  3. The http1.x solution to header blocking is to open multiple TCP connections, which is costly, whereas 2.0 can handle a single TCP connection
  4. Http1.x a single TCP connection can only handle one request at a time, whereas 2.0 can send multiple requests simultaneously

HTTP3.0

In HTTP2.0, multiple HTTP servers share a TCP connection. If packet loss occurs, the entire connection must wait for retransmission. This defect originates from the underlying protocol TCP. HTTP/2 has only one TCP connection, and the blocking problem is magnified. HTTP/2 has only one TCP connection.

TCP protocol has been widely used, it is difficult to change it, so HTTP/3.0 chose a compromise method – UDP protocol, HTTP/2 on the basis of UDP multiplexing, 0-RTT, TLS encryption, traffic control, packet loss retransmission and other functions.

After the speech

This article quotes from illustrated HTTP

The article juejin. Cn/post / 696393… The article coolshell. Cn/articles / 19…