Netty如何实现http2消息的封装细节?

2026-05-29 11:172阅读0评论SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计889个文字,预计阅读时间需要4分钟。

Netty如何实现http2消息的封装细节?

frame是HTTP/2中用于通信的最小单元,以下是一些常见的frame类型:DATA frame、HEADERS frame、PRIORITY frame、RST_STREAM frame、SETTINGS frame、ACK frame、PING frame、PONG frame。

frame 就是 http2 中进行通信的最小单位,根据上一节的介绍,我们知道 frame 有这样几种:

DATA frameHEADERS framePRIORITY frameRST_STREAM frameSETTINGS acknowledgment frameSETTINGS framePING framePING acknowledgmentPUSH_PROMISE frameGO_AWAY frameWINDOW_UPDATE frameUnknown Frame 我们看一下 http2 中 stream 和 frame 的一个大体的结构:

在 http2 中,一个 TCP 连接,可以承载多个数据流 stream,多个 stream 中的不同 frame 可以交错发送。

每个 frame 通过 stream id 来标记其所属的 stream。

有了上面的 http2 的基本概念,我们接下来就看下 netty 对 http2 的封装了。

netty 对 http2 的封装 Http2Stream 作为一个 TCP 连接下面的最大的单位 stream,netty 中提供了接口 Http2Stream。注意,Http2Stream 是一个接口,它有两个实现类,分别是 DefaultStream 和 ConnectionStream。

Http2Stream 中有两个非常重要的属性,分别是 id 和 state。

阅读全文

本文共计889个文字,预计阅读时间需要4分钟。

Netty如何实现http2消息的封装细节?

frame是HTTP/2中用于通信的最小单元,以下是一些常见的frame类型:DATA frame、HEADERS frame、PRIORITY frame、RST_STREAM frame、SETTINGS frame、ACK frame、PING frame、PONG frame。

frame 就是 http2 中进行通信的最小单位,根据上一节的介绍,我们知道 frame 有这样几种:

DATA frameHEADERS framePRIORITY frameRST_STREAM frameSETTINGS acknowledgment frameSETTINGS framePING framePING acknowledgmentPUSH_PROMISE frameGO_AWAY frameWINDOW_UPDATE frameUnknown Frame 我们看一下 http2 中 stream 和 frame 的一个大体的结构:

在 http2 中,一个 TCP 连接,可以承载多个数据流 stream,多个 stream 中的不同 frame 可以交错发送。

每个 frame 通过 stream id 来标记其所属的 stream。

有了上面的 http2 的基本概念,我们接下来就看下 netty 对 http2 的封装了。

netty 对 http2 的封装 Http2Stream 作为一个 TCP 连接下面的最大的单位 stream,netty 中提供了接口 Http2Stream。注意,Http2Stream 是一个接口,它有两个实现类,分别是 DefaultStream 和 ConnectionStream。

Http2Stream 中有两个非常重要的属性,分别是 id 和 state。

阅读全文