http2stream.respond([headers[, options]])
历史
版本 | 变化 |
---|---|
v14.5.0、v12.19.0 | 允许明确设置日期标题。 |
v8.4.0 | 添加于:v8.4.0 |
参数
headers
<HTTP/2 Headers Object>options
<Object>
const http2 = require('node:http2');
const server = http2.createServer();
server.on('stream', (stream) => {
stream.respond({ ':status': 200 });
stream.end('some data');
});
当设置options.waitForTrailers
选项时,将在排队要发送的最后一块有效负载数据后立即发出'wantTrailers'
事件。然后可以使用http2stream.sendTrailers()
方法将尾随标头字段发送到对等方。
当设置options.waitForTrailers
时,在传输最后一个DATA
帧时,Http2Stream
不会自动关闭。用户代码必须调用 http2stream.sendTrailers()
或 http2stream.close()
来关闭 Http2Stream
。
const http2 = require('node:http2');
const server = http2.createServer();
server.on('stream', (stream) => {
stream.respond({ ':status': 200 }, { waitForTrailers: true });
stream.on('wantTrailers', () => {
stream.sendTrailers({ ABC: 'some value to send' });
});
stream.end('some data');
});
相关用法
- Node.js http2stream.respond()用法及代码示例
- Node.js ServerHttp2Stream http2stream.respondWithFD(fd[, headers[, options]])用法及代码示例
- Node.js ServerHttp2Stream http2stream.respondWithFile(path[, headers[, options]])用法及代码示例
- Node.js http2stream.rstCode用法及代码示例
- Node.js ServerHttp2Stream http2stream.pushStream(headers[, options], callback)用法及代码示例
- Node.js http2stream.setTimeout()用法及代码示例
- Node.js http2stream.id用法及代码示例
- Node.js http2stream.closed用法及代码示例
- Node.js http2stream.pushAllowed用法及代码示例
- Node.js http2stream.sentHeaders用法及代码示例
- Node.js http2stream.endAfterHeaders用法及代码示例
- Node.js http2stream.pending用法及代码示例
- Node.js http2stream.headersSent用法及代码示例
- Node.js http2stream.close()用法及代码示例
- Node.js http2stream.state用法及代码示例
- Node.js http2stream.session用法及代码示例
- Node.js http2stream.destroyed用法及代码示例
- Node.js http2stream.additionalHeaders()用法及代码示例
- Node.js http2stream.priority()用法及代码示例
- Node.js http2stream.sentInfoHeaders用法及代码示例
- Node.js http2session.destroyed用法及代码示例
- Node.js http2session.type用法及代码示例
- Node.js http2session.ping()用法及代码示例
- Node.js http2session.connecting用法及代码示例
- Node.js http2session.setTimeout()用法及代码示例
注:本文由纯净天空筛选整理自nodejs.org大神的英文原创作品 http2stream.respond([headers[, options]])。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。