创建


在服务器端,ServerHttp2Stream 的实例是在以下任一情况下创建的:

  • 接收到新的 HTTP/2 HEADERS 帧,其中包含以前未使用的流 ID;
  • 调用了 http2stream.pushStream() 方法。

在客户端,ClientHttp2Stream 的实例是在调用 http2session.request() 方法时创建的。

在客户端,如果父 Http2Session 尚未完全建立,则 http2session.request() 返回的 Http2Stream 实例可能不会立即准备好使用。 在这种情况下,在 Http2Stream 上调用的操作将被缓冲,直到触发 'ready' 事件。 用户代码应该很少,如果有的话,需要直接处理 'ready' 事件。 Http2Stream 的就绪状态可以通过检查 http2stream.id 的值来确定。 如果值为 undefined,则流尚未准备好使用。

On the server side, instances of ServerHttp2Stream are created either when:

  • A new HTTP/2 HEADERS frame with a previously unused stream ID is received;
  • The http2stream.pushStream() method is called.

On the client side, instances of ClientHttp2Stream are created when the http2session.request() method is called.

On the client, the Http2Stream instance returned by http2session.request() may not be immediately ready for use if the parent Http2Session has not yet been fully established. In such cases, operations called on the Http2Stream will be buffered until the 'ready' event is emitted. User code should rarely, if ever, need to handle the 'ready' event directly. The ready status of an Http2Stream can be determined by checking the value of http2stream.id. If the value is undefined, the stream is not yet ready for use.