How does a browser know if a site supports HTTP/2?

主宰稳场 提交于 2019-12-09 14:09:30

问题


If I type out https://http2.golang.org/ the chrome browser will automatically send the HTTP/2 request. How is this done?


回答1:


Take stackoverflow for example, when the browser sends a request to stackoverflow.com, it has to do the following steps:

  1. DNS lookup. find the ip address of stackoverflow.
  2. TCP/IP handshake
  3. TLS handshake.
  4. HTTP request/response (Application Protocol).
  5. ....

TLS handshake

Regarding step3 TLS handshake, there is an nice explanation by @Oleg.

In order to inspect the detail of TCP/IP packet, You may need use some tools to capture packets. e.g. Wireshark.

Client sends ClientHello to server, which carries several things

  • supported cipher suite. which cipher suites do you like?
  • supported TLS version.
  • a random number.
  • the supported Application Protocols. e.g. HTTP/2, HTTP 1.1/ Spdy/..
  • ...

Server responds SeverHello, which carries

  • chosen cipher suite.
  • chosen TLS version.
  • a random generated number
  • And, chosen application protocols in TLS application-layer protocol negotiation (ALPN), e.g. HTTP/2

Conclusion

HTTP2 request/response happens in step4. Before that, browser has already know whether sever support HTTP/2 through TLS handshake.




回答2:


The chrome browser will only send a HTTP/1.1 Request to the website. As the website is HTTP/2 Enabled, it will send a message to the browser that it supports HTTP/2. The server upgrades the communication protocol between it and the server to HTTP/2 if it finds the browser capable of recognizing HTTP/2. So, it is generally the server which converts a request to the HTTP/2 Connection. The browser just complies with the upgrade policy of the server. The chrome browser displays that you have a HTTP/2 connection with the server or website, only after the server upgrades the communication protocol.




回答3:


The string "h2" identifies the protocol where HTTP/2 uses Transport Layer >Security (TLS) [TLS12]. This identifier is used in the TLS application-layer protocol negotiation (ALPN) >extension [TLS-ALPN] field and in any place where HTTP/2 over TLS is identified.

If server support http2.0 browser will find that server is support http2.0 in TLS application-layer protocol negotiation. refer link!



来源:https://stackoverflow.com/questions/37181601/how-does-a-browser-know-if-a-site-supports-http-2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!