1

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

3
  • 1
    The key there is "HTTP/2 only". An HTTP/2 client has the option of falling back to HTTP/1 if the HTTP/2 handshake fails. This would be normal for a web browser that wants to support as many web servers as possible. But suppose I write a new HTTP/2 RESTful API. I may not want to bother with supporting HTTP/1 and would just ignore old clients. Commented Sep 17, 2023 at 15:48
  • Thank you! It looks like it depends on how I develop the server. Should I write on front-end project code for this case by myself to be able falling back to HTTP/1.1? Or is it something that will happen automatically somehow? Commented Sep 17, 2023 at 16:01
  • It will depend on what middleware you use. You likely aren't writing the web server yourself, so a server or content delivery platform would have to support version 2. It been around since 2015 and there is a lot of support out there. Here is a wikipedia link with a non-comprehensive list of tools (its content will change over time): en.wikipedia.org/wiki/HTTP/2 Commented Sep 17, 2023 at 17:37

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.