Search code examples
http2

HTTP2: How to indicate support for it? Is there a "Alternate-Protocol" for HTTP2?


So I just upgraded to nginx 1.9.5 which supports HTTP2.

I replaced all listen spdy by listen http2, removed spdy_headers_comp directive and also removed add_header Alternate-Protocol 443:npn-spdy/3;

Then I opened my site in Firefox, opened network monitor, and voila: Version: HTTP/2.0

But how does Firefox know my site supports HTTP2? Does it always first try to connect via HTTP2 before trying HTTP1.1?


Solution

  • HTTP/2 sites are deployed over TLS.

    Browsers use a TLS extension called ALPN to tell the server what protocols they can speak. Browsers always send this TLS extension, and always include both HTTP/2 and HTTP/1.1 (and may also include the old SPDY protocol).

    The server receives the list of protocols that browsers can speak, and if the server supports HTTP/2 (and if a number of other conditions are met - in particular regarding the TLS protocol version and the cipher suite), the server decides to speak HTTP/2 with the browser, and sends the chosen protocol back to the browser, again using the ALPN extension.

    If the server does not support HTTP/2 then it will send to the browser that it can only speak HTTP/1.1 via the ALPN extension.

    If the server does not support the ALPN extension, then it will not send it to the browser, and the browser will default to speak HTTP/1.1 to that server.