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?
Asked Answered
A

3

12

HTTP/2 is definitely the future trend because it is now the standard of HTTP protocol. As we can see in Can I use, 70.15 percent of browsers support the HTTP/2. But HTTP/2 is so new that there are browsers that only support HTTP/1.x and there are many servers that only support HTTP/1.x. I knew that a client can use HTTP upgrade mechanism to negotiate a proper protocol to communicate with the server. For example, if the server supports HTTP/2, their communicating protocol will switch to HTTP/2, otherwise, HTTP/1.x is used. But this only applies to the situdation where the browser the clients used supports both HTTP/2 and HTTP/1.x, right?

But what if a user on a browser that only supports HTTP/1.x wants to communicate with HTTP/2 only server? Will the server ignore the request or send an error back to the user?

And what if a user on a brower that only supports HTTP/2 wants to communicate with HTTP/1.1 only server? I am thinking the process might go like this: The user sends a connecion preface to the server, the server cannot recognize the request, so the user might receive a connection error message. Is this right?

Or is there any browser that supports only HTTP/2?

Achlorhydria answered 8/4, 2016 at 12:52 Comment(0)
R
11

If a browser only supports HTTP/1.1 and the server only supports HTTP/2, they cannot communicate. The server will not recognize what the client sends (in particular there will be no connection preface, which the server treats - following the specification - as a connection error), and will close the connection.

"A browser that only supports HTTP/2" does not exist; if they support HTTP/2, they also support HTTP/1.1. But let's assume that such browser exist.

In this latter case, the server will see the connection preface and will not recognize the PRI method. What exactly the server does in this case depends on the server. It may return a 400 Bad Request, or perhaps just close the connection, or it may trigger an internal server error.

Ripleigh answered 8/4, 2016 at 13:51 Comment(1)
Yes, and this is the wrong behaviour of server, this is the bug for HTTP 1.1 parser server implementation. HTTP 1.1 parser should not panic when he see HTTP/2 connection preface.Athey
S
31

It's important to take in consideration that the most implementations of HTTP/2 uses it over TLS 1.2 with ALPN protocol (Application Layer Protocol Negotiation). Thus the client just start the standard TLS connection. As the part of such communication the client sends "Client Hello" to the server with some information:

enter image description here

It's like: "Hi, Tom! It's Bob. I speak German, Russian and English. Let's talk a little". And the server send "Server Hello":

enter image description here

"Hi, Bob! I suggest to speak German or English". Then the client send one more short message "OK, then let's speak German" and he start to speak German without waiting of any response from the server:

enter image description here

The whole communication looks like on the picture below

enter image description here

Because both the client and the server start the communication just using TLS 1.2, which the both know. They start the main communication after the protocol negotiation. Thus the problem which you describe could not exist in the practice.

Salience answered 8/4, 2016 at 17:33 Comment(5)
To work as you described, does the server need to support https? What if the server does not support https?Achlorhydria
@user3744927: Adding support of HTTPS and tuning it - it's the first step of implementation of HTTP/2. One can get now SSL/TLS certificate for free, for example from letsencrypt.org, startssl.com or other. The solution of letsencrypt.org is the most simple and powerful. Which operation system you use and which web server? I'd recommend you to install OpenSSL and get Let's encrypt certificate. Then to configure you server based on the suggestionsSalience
I am not implementing HTTP/2 server, I am curious HTTP/2 backward compatibility. Most browsers only support HTTP/2 over TLS, but there are still a great number of servers that do not support encryption. And what if some servers still prefer non encryption in HTTP/2?Achlorhydria
@user3744927: Such servers (without update to HTTP/2) will stay slowly. One see currently that the roll-out of HTTP/2 and TLS run very quickly. One can see here that it's about 0.1% in the week. I find it very quickly if one think about all serverSalience
Everything can exist in practice but tomorrow.Athey
R
11

If a browser only supports HTTP/1.1 and the server only supports HTTP/2, they cannot communicate. The server will not recognize what the client sends (in particular there will be no connection preface, which the server treats - following the specification - as a connection error), and will close the connection.

"A browser that only supports HTTP/2" does not exist; if they support HTTP/2, they also support HTTP/1.1. But let's assume that such browser exist.

In this latter case, the server will see the connection preface and will not recognize the PRI method. What exactly the server does in this case depends on the server. It may return a 400 Bad Request, or perhaps just close the connection, or it may trigger an internal server error.

Ripleigh answered 8/4, 2016 at 13:51 Comment(1)
Yes, and this is the wrong behaviour of server, this is the bug for HTTP 1.1 parser server implementation. HTTP 1.1 parser should not panic when he see HTTP/2 connection preface.Athey
F
1

I've tried to visit a http2 only server with curl --http1.1 -i, here is what I got

HTTP/1.0 403 Forbidden
Content-Type: text/plain

Unknown ALPN Protocol, expected `h2` to be available.
If this is a HTTP request: The server was not configured with the `allowHTTP1` option or a listener for the `unknownProtocol` event.
Friar answered 21/8, 2018 at 16:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.