http2: header 块逻辑等同于单帧

http2: header block logical equivalence to a single frame

来自http2 spec

Each header block is processed as a discrete unit. Header blocks MUST be transmitted as a contiguous sequence of frames, with no interleaved frames of any other type or from any other stream. The last frame in a sequence of HEADERS or CONTINUATION frames has the END_HEADERS flag set. The last frame in a sequence of PUSH_PROMISE or CONTINUATION frames has the END_HEADERS flag set. This allows a header block to be logically equivalent to a single frame.

我看到“作为连续的帧序列传输,没有任何其他类型或任何其他流的交错帧”如何使“header 块在逻辑上等同于单个帧”,但为什么与单个框架的逻辑等价如此重要,以至于偏离了 http2 其余部分的工作方式?

这很重要吗,因为 header 块的处理会更改 HPACK 上下文所持有的连接状态。

处理如下序列:

HEADERS[stream=3,end_headers=false], HEADERS[stream=5,end_headers=true], CONTINUATION[stream=3,end_headers=true]

您需要等待 CONTINUATION 帧到达,然后才能处理 stream=5HEADERS 帧。

现在,想象一个 发送那个 CONTINUATION 帧的恶意客户端:它有能力完全停止服务器上的帧处理并强制服务器缓冲所有到达的帧,等待 CONTINUATION 帧 - 不好。

因此,为了简化规范和协议,CONTINUATION 不能 交错,这是对所有帧的特殊处理其他 HTTP/2 帧 可以 交错。