在没有启用 ALPN 的时候,加载一个 HTTP/2 页面的步骤是:
Without ALPN, the steps to load a HTTP/2 page would be like:
- TLS 握手 (TLS handshake)
- 浏览器/客户端 发送带有 “Upgrade: h2c” 头的 HTTP/1.1 请求 (Browser/Client speaks HTTP/1.1 to server with “Upgrade: h2c” Header)
- 服务器回复 101 Switching 并将链接升级至 HTTP2 (Server responds with 101 Switching to upgrade to HTTP2)
- 现在服务器和客户端采用 HTTP2 协议交流 (Now they talks via HTTP2)
在启用了 ALPN 的情况下:
With ALPN, the steps would be:
- TLS握手,并且在握手过程中,客户端告诉服务器一个客户端支持的协议列表,然后服务器回复客户端支持 HTTP2 协议 (TLS handshake and in the handshake client tells the server the list of protocol it supports and server respond in handshake saying that it supports HTTP2 as well)
- 现在服务器和客户端采用 HTTP2 协议交流 (Now they talks via HTTP2)
可以看出,使用 ALPN 之后,客户端和服务器的交互少了一轮握手(不需要 Upgrade 和 101 Switching)
As you can see there is one less round trip with ALPN (No step of Upgrade and 101 Switching)
什么是 ALPN(应用层协议协商) What is ALPN (Application-Layer Protocol Negotiation) by c11e is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.