创建


【Creation】

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

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

  • 接收到一个具有先前未使用的流 ID 的新的 HTTP/2 HEADERS 帧;
  • http2stream.pushStream() 方法被调用。

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

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

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

【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.】