事件:'response'
【Event: 'response'】
headersHTTP/2 头对象flags<number>
'response' 事件在从已连接的 HTTP/2 服务器接收到该流的 HEADERS 响应帧时触发。监听器会接收两个参数:一个包含接收到的 HTTP/2 头部对象 的 Object,以及与这些头相关的标志。
【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 two arguments: an Object containing the received
HTTP/2 Headers Object, and flags associated with the 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']);
});