首页 > http2 > 如果HTTP / 1.1客户端与仅HTTP / 2服务器通信以及如果HTTP / 2客户端与仅HTTP / 1.1服务器通信怎么办?

如果HTTP / 1.1客户端与仅HTTP / 2服务器通信以及如果HTTP / 2客户端与仅HTTP / 1.1服务器通信怎么办? (What if an HTTP/1.1 client talk to an HTTP/2 only server and what if an HTTP/2 client talk to an HTT)

2016-04-08 http2http-1.1

问题

HTTP / 2肯定是未来趋势,因为它现在是HTTP协议的标准。我们可以在使用中看到,70.15%的浏览器支持HTTP / 2。但HTTP / 2是如此新颖,以至于只有支持HTTP / 1.x的浏览器,并且有许多服务器只支持HTTP / 1.x. 我知道客户端可以使用HTTP升级机制来协商正确的协议以与服务器通信。例如,如果服务器支持HTTP / 2,则它们的通信协议将切换到HTTP / 2,否则使用HTTP / 1.x. 但这仅适用于客户端使用的浏览器同时支持HTTP / 2和HTTP / 1.x的情况,对吗?

但是,如果浏览器上仅支持HTTP / 1.x的用户想要与仅HTTP / 2服务器通信呢?服务器是否会忽略该请求或将错误发送回用户?

如果只支持HTTP / 2的浏览器上的用户想要与仅HTTP / 1.1服务器通信呢?我认为这个过程可能是这样的:用户向服务器发送连接前言,服务器无法识别请求,因此用户可能会收到连接错误消息。这是正确的吗?

或者是否有任何浏览器仅支持HTTP / 2?

解决方法

如果浏览器仅支持HTTP / 1.1且服务器仅支持HTTP / 2,则它们无法通信。服务器无法识别客户端发送的内容(特别是没有连接前言,服务器会按照规范处理 - 作为连接错误),并将关闭连接。

“不支持HTTP / 2的浏览器”不存在; 如果它们支持HTTP / 2,它们也支持HTTP / 1.1。但是我们假设存在这样的浏览器。

在后一种情况下,服务器将看到连接前言,并且不会识别该PRI方法。在这种情况下,服务器究竟做了什么取决于服务器。它可能返回一个400 Bad Request,或者可能只是关闭连接,或者它可能触发内部服务器错误。

问题

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?

解决方法

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.

相似信息