http2stream.pushStream(headers[, options], callback)
headersHTTP/2 头对象options<Object>callback<Function> 推送流启动后调用的回调函数。err<Error>pushStream<ServerHttp2Stream> 返回的pushStream对象。headersHTTP/2 Headers 对象pushStream启动时使用的 Headers 对象。
启动一个推送流。回调会被调用,并传入为推送流创建的新 Http2Stream 实例作为第二个参数,或者传入一个 Error 作为第一个参数。
【Initiates a push stream. The callback is invoked with the new Http2Stream
instance created for the push stream passed as the second argument, or an
Error passed as the first argument.】
const http2 = require('node:http2');
const server = http2.createServer();
server.on('stream', (stream) => {
stream.respond({ ':status': 200 });
stream.pushStream({ ':path': '/' }, (err, pushStream, headers) => {
if (err) throw err;
pushStream.respond({ ':status': 200 });
pushStream.end('some pushed data');
});
stream.end('some data');
}); 在 HEADERS 帧中不允许设置推送流的权重。请将 weight 值传递给 http2stream.priority,并将 silent 选项设置为 true,以启用服务器端并发流之间的带宽平衡。
【Setting the weight of a push stream is not allowed in the HEADERS frame. Pass
a weight value to http2stream.priority with the silent option set to
true to enable server-side bandwidth balancing between concurrent streams.】
在已推送的流中调用 http2stream.pushStream() 是不允许的,会抛出错误。
【Calling http2stream.pushStream() from within a pushed stream is not permitted
and will throw an error.】