httpprotocolshttp2network-protocolshttp-1.1

How can server with HTTP 1.1 understand client that uses HTTP 2?


I'm confused because it looks for me like different sources says different things, I don't really understand it:

The "layer" refers to a design choice to introduce a new optimized encoding mechanism between the socket interface and the higher HTTP API exposed to our applications: the HTTP semantics, such as verbs, methods, and headers, are unaffected, but the way they are encoded while in transit is what’s different. Unlike the newline delimited plaintext HTTP/1.x protocol, all HTTP/2 communication is split into smaller messages and frames, each of which is encoded in binary format. As a result, both client and server must use the new binary encoding mechanism to understand each other: an HTTP/1.x client won’t understand an HTTP/2 only server, and vice versa.

it's possible for an HTTP/2-capable client to send an HTTP/2 request to a server. However, if the server only supports HTTP/1.1 and doesn't understand HTTP/2, it will respond with an HTTP/1.1 response. This situation can occur when a client attempts to use the newer HTTP/2 protocol with a server that hasn't yet adopted it.

I learned that they have different formats of data: HTTP 1.1 contains text while HTTP 2 contains binary data. I tried to google it and even tried to translate it because English is not my native language.

I also found this What if an HTTP/1.1 client talk to an HTTP/2 only server and what if an HTTP/2 client talk to an HTTP/1.1 only server?

Also there are frames and table for headers compression in HTTP2


Solution

  • First things first;

    it's possible for an HTTP/2-capable client to send an HTTP/2 request to a server. However, if the server only supports HTTP/1.1 and doesn't understand HTTP/2, it will respond with an HTTP/1.1 response. This situation can occur when a client attempts to use the newer HTTP/2 protocol with a server that hasn't yet adopted it.

    this is kinda wrong, when a HTTP/2 only server receives a HTTP/1.1 request, because it cant understand it, there would be a error on the server side, so client probably can't parse the response or there would be no response based on the server implementation. In practise, nearly all servers support both protocols. thats why the quoted texts says it like that. it is confusing.

    That sentence should be like this;

    "if the server only supports HTTP/1.1 and doesn't understand HTTP/2, client will send a HTTP/1.1 request and server will response in HTTP/1.1. if client doesn't support HTTP/1.1, client would throw a error"

    When TLS handshake happens, server sends ALPN protocols, which is a string list of supported protocols, for most servers out there it is ["h2","http1.1"], then client looks if there is a supported protocol there, choses one by the order specified from server. So for your front-end project you dont need to specify anything about HTTP/2 or HTTP/1.1, browser handles that protocol negotiation automatically.

    The stackoverflow answer you linked explains it really great.