http2stream.sendTrailers(headers)
添加於:v10.0.0
參數
headers
<HTTP/2 Headers Object>
將尾隨的 HEADERS
幀發送到連接的 HTTP/2 對等體。此方法將導致 Http2Stream
立即關閉,並且隻能在發出 'wantTrailers'
事件後調用。發送請求或發送響應時,必須設置 options.waitForTrailers
選項,以便在最終 DATA
幀之後保持 Http2Stream
打開,以便可以發送預告片。
const http2 = require('node:http2');
const server = http2.createServer();
server.on('stream', (stream) => {
stream.respond(undefined, { waitForTrailers: true });
stream.on('wantTrailers', () => {
stream.sendTrailers({ xyz: 'abc' });
});
stream.end('Hello World');
});
HTTP/1 規範禁止預告片包含 HTTP/2 pseudo-header 字段(例如 ':method'
、 ':path'
等)。
相關用法
- Node.js Http2Stream.setTimeout(msecs, callback)用法及代碼示例
- Node.js Http2Stream close用法及代碼示例
- Node.js Http2Stream Headers用法及代碼示例
- Node.js Http2Stream Response用法及代碼示例
- Node.js Http2Stream用法及代碼示例
- Node.js Http2Stream Timeout用法及代碼示例
- Node.js Http2ServerResponse.finished用法及代碼示例
- Node.js Http2Session stream用法及代碼示例
- Node.js Http2ServerResponse.getHeaderNames()用法及代碼示例
- Node.js Http2Session.ping([payload, ]callback)用法及代碼示例
- Node.js Http2ServerResponse.statusMessage用法及代碼示例
- Node.js Http2ServerResponse.writableEnded用法及代碼示例
- Node.js Http2Session timeout用法及代碼示例
- Node.js Http2ServerRequest.stream用法及代碼示例
- Node.js Http2ServerResponse.setHeader()用法及代碼示例
- Node.js Http2ServerRequest.method用法及代碼示例
- Node.js Http2ServerResponse.getHeader()用法及代碼示例
- Node.js Http2ServerResponse.addTrailers()用法及代碼示例
- Node.js Http2ServerRequest.url用法及代碼示例
- Node.js Http2ServerResponse.setTimeout()用法及代碼示例
- Node.js Http2ServerRequest.complete用法及代碼示例
- Node.js Http2ServerResponse.stream用法及代碼示例
- Node.js Http2ServerRequest.destroy()用法及代碼示例
- Node.js Http2ServerResponse.removeHeader()用法及代碼示例
- Node.js Http2ServerResponse.hasHeader()用法及代碼示例
注:本文由純淨天空篩選整理自nodejs.org大神的英文原創作品 Http2Stream.sendTrailers(headers)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。