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]])。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。