Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

http2

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

like image 365
fengsp Avatar asked May 12 '16 08:05

fengsp


People also ask

How does browser know http2?

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.

How can I tell if HTTP 2 is supported?

Google Chrome offers a quick and easy way to check if HTTP/2 is supported on your SSL-enabled site. First, visit your site in Chrome over HTTPS. There you'll see your site listed with protocol h2, confirming your site works over HTTP/2.

Does my browser support http2?

In browsers, HTTP/2 is supported by the most current releases of Edge, Safari, Firefox and Chrome. Other browsers based upon Blink will also support HTTP/2 (e.g., Opera and Yandex Browser).

How do I enable HTTP 2 on my browser?

HTTP/2 settings can be configured in the Profile Settings. In the menu, click Settings > Active Profile > Web (Protocol Level). HTTP/2 is disabled by default. To enable it, set the Preferred HTTP version to HTTP/2 .


1 Answers

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/..
  • ...

Client Hello

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

enter image description here

Conclusion

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

like image 194
Ryan Lyu Avatar answered Sep 22 '22 10:09

Ryan Lyu