YuezhenQin / javaweb

0 stars 0 forks source link

HTTP1, HTTP2, HTTP3 a deep dive #14

Open YuezhenQin opened 1 month ago

YuezhenQin commented 1 month ago

In today’s deep dive, we’ll unravel the evolution of HTTP, from its beginnings with HTTP1 to the latest advancements of HTTP2 and HTTP3. We’ll look at how each version addressed the limitations of its predecessor, improving performance and user experience.

YuezhenQin commented 1 month ago

By the end of this article, you’ll have a solid understanding of the key differences between HTTP1, HTTP2, and HTTP3, helping you make informed decisions when designing web applications.

YuezhenQin commented 1 month ago

HTTP1 - The Foundation

HTTP/1 was introduced in 1996. Before that, there was HTTP/0.9, a protocol that only supported the GET as request method. Only HTML files were included in HTTP responses.

HTTP/1.0 added headers, status codes, and additional request methods such as POST and HEAD. However, HTTP/1 still had limitations. For example, each request-response pair needed a new TCP connection

In 1997, HTTP/1.1 was released to address the limitations of HTTP/1. Generally speaking, HTTP/1.1 is the definitive version of HTTP1.

What contributed to its incredible longevity?

YuezhenQin commented 1 month ago

1 - Persistent Connections (持久连接)

As mentioned, HTTP started as a request-response protocol.

A client opens a connection to the server, makes a request, and gets the response. The connection is then closed. If there’s a second request, the cycle repeats. The same cycle repeats for subsequent requests (HTTP 最初是一种单纯的请求-响应协议。客户端打开与服务器的连接,发出请求并获取响应。响应之后连接即刻关闭。如果有第二个请求,则重复该循环。对于后续请求,重复相同的循环).

As the web became more media-oriented, closing the connection constantly after every response proved wasteful. If a web page contains multiple resources that have to be fetched, you would have to open and close the connection multiple times.

Since HTTP/1 was built on top of TCP (Transmission Control Protocol), every new connection meant going through the 3-way handshake process.

HTTP/1.1 got rid of this extra cost by supporting persistent connections. It assumed that a TCP connection must be kept open unless directly told to close (TCP 连接将保持开启,直到被告知关闭. 而在此之前一次请求-响应之后连接就会被关闭. )

It means no closing after every request.

source: https://blog.bytebytego.com/p/http1-vs-http2-vs-http3-a-deep-dive?utm_source=substack&utm_medium=email

YuezhenQin commented 1 month ago

2 - Pipelining (多通道)

HTTP pipelining is a technique in which multiple HTTP requests are sent on a single TCP connection without waiting for the corresponding responses. This allows the client to send multiple requests before any responses are received, potentially reducing the overall latency and improving the efficiency of the network connection.

HTTP 多通道技术是一种在单个 TCP 连接上在一个时刻发送多个 HTTP 请求,而不等待相应响应的技术。这允许客户端在收到任何响应之前发送多个请求

Unfortunately, pipelining wasn’t well supported by web browsers due to implementation difficulties, and as a result, it was rarely used.

Also, pipelining was still prone to another problem known as head-of-line (HOL) blocking, in which a blocked request at the head of the queue can block all the requests behind it.

YuezhenQin commented 1 month ago

3 - Chunked Transfer Encoding (分块传输编码)

HTTP/1.1 introduced chunked transfer encoding that allowed servers to send responses in smaller chunks rather than waiting for the entire response to be generated.