HTTP / 2是无状态协议吗? [英] Is HTTP/2 a stateless protocol?

查看:448
本文介绍了HTTP / 2是无状态协议吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据我的理解, HTTP / 2 附带一个名为 HPACK 的有状态标头压缩。它不会改变HTTP协议的无状态语义吗? Web应用程序将 HTTP / 2 视为无状态协议是否安全?最后, HTTP / 2 是否与现有的负载均衡器兼容?

From my understanding, HTTP/2 comes with a stateful header compression called HPACK. Doesn't it change the stateless semantics of the HTTP protocol? Is it safe for web applications to consider HTTP/2 as a stateless protocol? Finally, will HTTP/2 be compatible with the existing load balancers?

推荐答案

< h2> HTTP / 2是无状态的。

原始HTTP是无状态协议,这意味着可以孤立地理解每个请求消息。这意味着每个请求都需要带来与服务器提供服务所需的详细信息,而服务器不必存储来自先前请求的大量信息和元数据。

HTTP/2 is stateless.

Original HTTP is a stateless protocol, meaning that each request message can be understood in isolation. This means that every request needs to bring with it as much detail as the server needs to serve that request, without the server having to store a lot of info and meta-data from previous requests.

由于HTTP / 2不改变这种范式,它必须以相同的方式工作,无状态。

Since HTTP/2 doesn't change this paradigm, it has to work the same way, stateless.

oficial RFC 。据说:


超文本传输​​协议(HTTP)是一种用于分布式协作超媒体信息系统的应用程序级协议。它是一个通用的无状态协议,可以用于许多任务......

The Hypertext Transfer Protocol (HTTP) is an application-level protocol for distributed, collaborative, hypermedia information systems. It is a generic, stateless, protocol which can be used for many tasks...

HTTP / 2 的定义说:


此规范描述了超文本传输​​协议(HTTP)语义的优化表达式,称为HTTP版本2(HTTP / 2)......此规范是替代,但不是过时的,HTTP / 1.1消息语法。 HTTP的现有语义保持不变。



Conlusion



HTTP / 2协议在设计上是无状态的,因为语义与原始HTTP相比保持不变。

Conlusion

HTTP/2 protocol is stateless by design, as semantics remain unchanged in comparison to original HTTP.

HTTP / 2连接是在TCP连接之上运行的应用层协议(BTW,没有什么能阻止你使用 HTTP上的HTTP 例如,它是可能的,但不使用UDP,因为它不是可靠的传输 )。不要将它与会话和传输层混合使用。 HTTP协议无设计
加密SSL / TLS连接上的HTTP也不会对此语句进行任何更改,因为HTTP S 中的S与传输有关,而与协议本身无关。

An HTTP/2 connection is an application-layer protocol running on top of a TCP connection (BTW, nothing stops you to use HTTP over UDP for example, it's possible, but UDP is not used because it is not a "reliable transport"). Don't mix it with session and transport layers. HTTP protocol is stateless by design. HTTP over an encrypted SSL/TLS connection, also changes nothing to this statement, as S in HTTPS is concerned with the transport, not the protocol itself.

HPACK ,HTTP / 2的标头压缩,是一种专为HTTP / 2标头设计的压缩格式,它在单独的互联网中指定草案。它不会改变HTTP / 2本身,因此它不会改变语义。

HPACK, Header Compression for HTTP/2, is a compression format especially crafted for HTTP/2 headers, and it is being specified in a separate internet draft. It doesn't change HTTP/2 itself, so it doesn't change the semantics.

RFC for HTTP / 2 在关于HPACK的部分中说明:

In RFC for HTTP/2 in section about HPACK they state:


标头压缩是有状态的。一个压缩上下文和一个
解压缩上下文用于整个连接的

Header compression is stateful. One compression context and one decompression context are used for the entire connection.

这里是为什么来自 HPACK的RFC


2.2。编码和解码上下文

要解压缩标头块,解码器只需将
动态表(参见第2.3.2节)维护为解码上下文。不需要其他
动态状态。

To decompress header blocks, a decoder only needs to maintain a dynamic table (see Section 2.3.2) as a decoding context. No other dynamic state is needed.

当用于双向通信时,例如在HTTP中,
编码和解码动态表由端点是
完全独立,即请求和响应动态表
是分开的。

When used for bidirectional communication, such as in HTTP, the encoding and decoding dynamic tables maintained by an endpoint are completely independent, i.e., the request and response dynamic tables are separate.

HPACK 通过利用HTTP等协议中固有的
冗余来减少头字段编码的长度。
的最终目标是减少发送HTTP
请求或响应所需的数据量。

HPACK reduces the length of header field encodings by exploiting the redundancy inherent in protocols like HTTP. The ultimate goal of this is to reduce the amount of data that is required to send HTTP requests or responses.

HPACK实现不能完全无状态,因为完全独立的编码和解码表必须由端点维护。

An HPACK implementation cannot be completely stateless, because the encoding and decoding tables, completely independent, have to be maintained by an endpoint.

同时,有些库试图解决HPACK问题,例如无状态事件驱动的HPACK编解码器 CASHPACK

At the same time, there are libraries, which try to solve HPACK issues, for example, a stateless event-driven HPACK codec CASHPACK:


HPACK实现不能完全无状态,因为需要维护动态表。依赖于HTTP / 2将始终解码完整HPACK序列的假设,使用事件驱动的API实现无状态。

这篇关于HTTP / 2是无状态协议吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆