HTTP protocol knowledge is actually a lot of, the following simple summary of related concepts.

First, we need to have a basic idea of the network model. It is usually said that the 7-layer model / 4-layer model, in fact, the complete network model is 7-layer, to simplify, extend the 4-layer TCP/IP model concept. It is represented by the following figure

Four floors

  • 1. Application layer: The top three application layer, presentation layer, and session layer are combined together and are related to HTTP
  • 2. Transport layer: TCP, UDP, Socket, port
  • 3. At the network layer, IP addresses are routing-related
  • 4. Data link layer: Combine the lowest data link layer with the physical layer. MAC addresses are related

The main thing we know is the application layer, HTTP protocol. As you can see, HTTP is built on TOP of TCP, so we must also understand TCP connections.

Key differences between HTTP1.0 and HTTP1.1:

1. TCP connection. TCP provides a reliable, connection-oriented, byte stream, transport layer service that establishes a connection using a three-way handshake. Use 4 waves to close a connection. Http1.0 is like a man who cheats on women’s feelings and throws it away. Http1.1 is a bit longer and allows persistent connections to be set up to make multiple requests using a single TCP connection.

The three-way handshake is actually a confirmation of the status of the client and server. Both ends must have the sending and receiving capabilities.

First handshake: The client sends a network packet and the server receives it. The server concludes that the sending capability of the client and receiving capability of the server are normal.

Second handshake: The server sends the packet and the client receives it. The client concludes that the receiving and sending capabilities of the server and the client are normal.

Third handshake: The client sends the packet and the server receives it. The server concludes that the receiving and sending capabilities of the client and the sending and receiving capabilities of the server are normal.

Under normal conditions, the connection is established and data can be transferred.

Four waves were the end of the connection. Reduce it to the following dialogue

  • Initiator: ‘Hey, I’m closing it’
  • Recipient: ‘Ah, wait, that’s a bit sudden, give me a minute’
  • Recipient: ‘I’m done’
  • Initiator: ‘Ok, bye bye’

First wave: The active closing party sends a FIN that shuts down the data transfer from the active to the passive closing party. This is when the active closing party tells the passive closing party: I will not send you any more data.

After receiving the FIN packet, the sender sends an ACK with the received SEQUENCE number +1(the same as SYN, one FIN occupies one SEQUENCE number). Let them know I’ve received the shutdown request.

Third wave after the data processing is complete, the passive close sends a FIN to close the data transmission from the passive close to the active close, that is, to tell the active close, MY data has also been sent, will not send you any more data.

After the active closing party receives the FIN for the fourth wave, it sends an ACK to the passive closing party and confirms that the serial number is +1. Thus, the four waves are completed. I already know you’re done. We’re done.

HTTP1.0 specifies that the browser maintains a transient connection to the server. Each browser request requires a TCP connection to the server. The server disconnects the TCP connection as soon as the request is processed.

For example, a WEB page contains many image file does not contain the real image data content, just indicate the image URL, when the WEB browser to access this page file, the browser first to send the request in the page file, when the browser parses WEB server returns the page document HTML content, After the IMG image tag is found, the browser will send a request to the server to download the image data again according to the URL address specified by the SRC attribute in the IMG tag.

HTTP1.1 supports persistent connections, which allow multiple HTTP requests and responses to be sent over a single TCP connection, reducing the cost and latency of establishing and closing connections.

Multiple requests and replies for a web page file containing many images can be transferred in a single connection, but each request and reply for a separate web page file still needs to use its own connection. HTTP 1.1 also allows a 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.1 also improves and extends HTTP 1.0 by adding more request and response headers.

For example,

-host Host name field, which can be used to specify which WEB site on the server to access. -connection Request header value is keep-alive, the client notifies the server to return the result of this request to Keep the Connection. -Cookie state management -referer, which resource to access the server from. -user-agent, request environment, such as browser kernel-cache, force-cache priority over comparison cache-force-cache cache-contorl: No-cache, no-store, public, private, or max-age=0, must-revalidate Controls the browser's cache compared to http1.0's Expires field. Cache last-modified & if-modified-since: not requested server, disk cache, status code 200 If you force cache invalidation, compare the cache to determine whether to refresh the resource. If the resource update rate is less than seconds, the cache should not be used because the minimum time unit is seconds. If the file is dynamically generated by the server, the update time for this method is always the generation time, even though the file may not have changed, so it does not work as a cache. Etag & if-none-match (last-modified) : Etag & if-none-match (last-modified) : The Etag field and the file hash that it represents, that is to compare content - across domains, versus jSONP, which can only use GET requests, which supports all types of requests - simple requests, - Set access-Control-allow-origin to accept all cross-domain requests. You can also specify the source to enhance securityCopy the code
Third, HTTP1.1 adds more request methods

Http1.0 has three request methods: GET, POST, and HEAD.

Http1.1 adds six new request methods: OPTIONS, PUT, PATCH, DELETE, TRACE, and CONNECT

Key differences between HTTP1.1 and HTTP2.0

Binary framework layer

From a technical point of view, the biggest difference between HTTP1.1 and 2.0 is the binary framework layer. Unlike HTTP1.1, which treats all requests and responses as plain text, HTTP2 uses a binary framework layer to encapsulate all messages in binary while still maintaining HTTP syntax. The translation of messages allows HTTP2 to experiment with transport modes that HTTP1.1 cannot.

Http1.1 efficiently handles resource requests by introducing long connections and pipelining techniques. Long connections allow clients to send multiple requests over the same connection. But there is a bottleneck to this strategy. When a header request does not receive a resource in response, it will block subsequent requests. This is known as queue head blocking. That is, a connection can send multiple requests, but must wait for the next request to complete before processing can begin. While adding parallel TCP connections can alleviate this problem, the number of TCP connections is limited, and each new connection requires additional resources. Chrome allows a maximum of six TCP connections to a Host domain name.

In contrast to HTTP1.1, which leverages multiple TCP connections to reduce the impact of queue header blocking, HTTP2 establishes a single connection at both ends. This connection contains multiple data streams. Each flow contains multiple messages in request/response format. Eventually, each message is divided into smaller frame units. Interleaved requests and responses can be transmitted in parallel without being blocked. This process is called multiplexing.

In contrast to HTTP1.1, this means processing multiple requests simultaneously over the same TCP connection. So you have better network and bandwidth utilization.

Http2.0 allows developers to customize the weight of requests.

Anticipate resource requests

Because HTTP2 supports multiple concurrent responses, the server can send additional resources from the HTML page to it ahead of the client’s request. The home page style file resource, for example, can be pushed when an HTML page is requested.

Common status code

2XX — indicates that the request was processed normally

1. 200 OK: The request is processed normally.

204 No Content: The request is processed successfully, but No resources can be returned to the client. It is used when only information needs to be sent from the client to the server, but No new information needs to be sent to the client.

206 Partial Content: indicates a request for a part of a resource. This status code indicates that the client made a range request and the server successfully executed the Partial Content request. The response message contains the entity Content in the Range specified by content-range.

3XX – indicates that the browser needs to perform some special processing to properly process the request

301 Moved Permanently: The URI of the resource has been updated, so update your bookmark reference. Permanent redirect. The requested resource has been assigned a new URI, and the URI to which the resource now refers should be used later.

302 Found: The URI of the resource has been temporarily located elsewhere, assuming you already know this. Temporary redirection. This is similar to 301, but 302 represents a resource that is not permanently moved, but temporary in nature. In other words, the URI of a resource that has been moved may change in the future.

6, 303 See Other: The URI of the resource has been updated. Can you temporarily access the resource according to the new URI? This status code indicates that because another URL exists for the requested resource, the GET method should be used to GET the requested resource. The 303 status code and the 302 status code have the same functions, but the 303 status code clearly indicates that the client should use the GET method to obtain resources, which is different from the 302 status code.

When the 301,302,303 response status code is returned, almost all browsers change POST to GET and remove the body from the request message, after which the request is automatically sent again.

7, 304 Not Modified: The resource was found but did Not meet the condition request. The status code indicates that when the client sends a request with conditions (If the request packet using the GET method contains if-match, if-modified-since, if-none-match, if-range, and if-match), If- unmodified-since any header) the server allows the request to access the resource, but returns 304 If the condition is not met.

8, 307 Temporary Redirect: Temporary Redirect. Has the same meaning as 302.

4XX — Client error.

9. 400 Bad Request: The server cannot understand the Request sent by the client. Syntax errors may exist in the Request packet.

401 Unauthorized: This status code indicates that the request to be sent requires AUTHENTICATION information that is authenticated through HTTP (BASIC authentication).

403 Forbidden: Access to that resource is Forbidden. This status code indicates that access to the requested resource was denied by the server. (Permissions, unauthorized IP, etc.)

404 Not Found: The requested resource was Not Found on the server. Path error.

5XX — Server side error

13, 500 Internal Server Error: It appears that the Internal resource is faulty. This status code indicates that an error occurred on the server side while executing the request. It is also possible that the Web application has a bug or some temporary glitch.

14, 503 Service Unavailable: Sorry, I’m busy right now. This status code indicates that the server is temporarily overloaded or is down for maintenance and cannot process requests at this time.