• Do modern browsers disconnect after an HTTP request is completed after establishing a TCP connection with the server? When will it be disconnected?

  • How many HTTP requests can a TCP connection correspond to?

  • Can HTTP requests sent in a TCP connection be sent together (e.g., three requests sent together and three responses received together)?

  • Why do you sometimes refresh pages without re-establishing SSL connections?

  • Does the browser limit the number of TCP connections to the same Host?

Take your time. Let’s take it one by one


First question

Do modern browsers disconnect after an HTTP request is completed after establishing a TCP connection with the server? When will it be disconnected?

The Connection attribute in the request header determines whether the Connection is persistent.

In HTTP/1.0, Connection is close by default, that is, TCP connections are re-established and disconnected on each request. In HTTP/1.1, Connection is keep-alive by default, which means that TCP connections can be reused without having to re-establish and disconnect TCP connections every time.

Generally, if the TCP connection is not used by any other connection after the timeout period is set, the TCP connection is automatically disconnected.

A: By default, establishing a TCP Connection does not break. Only declaring Connection: close in the request header will close the Connection after the request completes.


Second question

How many HTTP requests can a TCP connection correspond to?

Answer: You can see from the previous question that a TCP connection can send multiple HTTP requests if the connection is maintained


Third question

Can HTTP requests sent in a TCP connection be sent together (e.g., three requests sent together and three responses received together)?

A single TCP connection can process only one request at a time. The life cycles of two HTTP requests cannot overlap. Any two HTTP requests cannot overlap in the same TCP connection from start to end. Pipelining is specified in the HTTP/1.1 specification to address this problem, but it is turned off by default in browsers.

Pipelining has many problems in practice:

  • Some proxy servers cannot handle HTTP Pipelining correctly
  • Head of line Blocking: After a TCP connection is established, it is assumed that the client sends multiple consecutive requests to the server on that connection. By standard, the server should return the results in the order it received the requests. Assuming that the server takes a lot of time to process the first request, all subsequent requests will have to wait for the end of the first request to respond, causing a block.

HTTP2 provides multiplex Multiplexing, which allows multiple HTTP requests to be completed simultaneously over a TCP connection.

The answer:



HTTP / 1.1
The browser is closed by default.
Is not workable



HTTP2
Multiplexing
Multiple HTTP
parallel


Fourth question

Why do you sometimes refresh pages without re-establishing SSL connections?

Answer: TCP connections are sometimes maintained by browsers and servers for a period of time. TCP does not need to be re-established, SSL will naturally use the previous.


Fifth question

Does the browser limit the number of TCP connections to the same Host?

Answer: Yes. Chrome allows up to six TCP connections to the same Host, with some differences between browsers.


The final chapter

If the HTML you receive contains dozens of image tags, how and in what order were the images downloaded, how many connections were made, and what protocol was used?

Multiplex = HTTP2; multiplex = HTTP2; multiplex = HTTP2; multiplex = HTTP2; multiplex = HTTP2 But also would not necessarily all hang in the domain of resources will be to use a TCP connection to get, but what is certain is Multiplexing is likely to be used.

What if HTTP2 cannot be used? Or you can’t use HTTPS (in real life HTTP2 is implemented over HTTPS, so you can only use HTTP/1.1). The browser establishes multiple TCP connections on the same HOST. The maximum number of connections depends on the browser Settings. These connections are used by the browser to send new requests during idle time.