事件:'response'


【Event: 'response'

  • headers HTTP/2 头对象
  • flags <number>
  • rawHeaders HTTP/2 原始头信息

当从已连接的 HTTP/2 服务器接收到响应的 HEADERS 帧时,会触发 'response' 事件。监听器会接收三个参数:一个包含接收到的 HTTP/2 头部对象Object、与该头部相关的标志,以及原始格式的头部(见 HTTP/2 原始头)。

【The 'response' event is emitted when a response HEADERS frame has been received for this stream from the connected HTTP/2 server. The listener is invoked with three arguments: an Object containing the received HTTP/2 Headers Object, flags associated with the headers, and the headers in raw format (see HTTP/2 Raw Headers).】

import { connect } from 'node:http2';
const client = connect('https://localhost');
const req = client.request({ ':path': '/' });
req.on('response', (headers, flags) => {
  console.log(headers[':status']);
});const http2 = require('node:http2');
const client = http2.connect('https://localhost');
const req = client.request({ ':path': '/' });
req.on('response', (headers, flags) => {
  console.log(headers[':status']);
});