serverhttp2session.altsvc(alt, originOrStream)
添加於:v9.4.0
參數
alt
<string> 由 RFC 7838 定義的替代服務配置的說明。originOrStream
<number> | <string> | <URL> | <Object> 指定來源的 URL 字符串(或帶有origin
屬性的Object
)或由http2stream.id
屬性給出的活動Http2Stream
的數字標識符。
向連接的客戶端提交 ALTSVC
幀(由 RFC 7838 定義)。
const http2 = require('node:http2');
const server = http2.createServer();
server.on('session', (session) => {
// Set altsvc for origin https://example.org:80
session.altsvc('h2=":8000"', 'https://example.org:80');
});
server.on('stream', (stream) => {
// Set altsvc for a specific stream
stream.session.altsvc('h2=":8000"', stream.id);
});
發送具有特定流 ID 的 ALTSVC
幀表示備用服務與給定 Http2Stream
的來源相關聯。
alt
和原始字符串必須僅包含 ASCII 字節,並被嚴格解釋為 ASCII 字節序列。可以傳遞特殊值'clear'
以清除任何先前為給定域設置的替代服務。
當為 originOrStream
參數傳遞一個字符串時,它將被解析為 URL 並派生源。例如,HTTP URL 'https://example.org/foo/bar'
的來源是 ASCII 字符串 'https://example.org'
。如果給定的字符串無法解析為 URL 或無法派生有效的來源,則會引發錯誤。
URL
對象或具有 origin
屬性的任何對象都可以作為 originOrStream
傳遞,在這種情況下,將使用 origin
屬性的值。 origin
屬性的值必須是正確序列化的 ASCII 源。
相關用法
- Node.js ServerHttp2Session.origin(...origins)用法及代碼示例
- Node.js MySQL SUBSTRING()用法及代碼示例
- Node.js SyntaxError用法及代碼示例
- Node.js Stream.pipeline()用法及代碼示例
- Node.js Sign用法及代碼示例
- Node.js MySQL SUM()用法及代碼示例
- Node.js ServerHttp2Stream http2stream.pushStream(headers[, options], callback)用法及代碼示例
- Node.js http2.Http2ServerRequest request.url用法及代碼示例
- Node.js request.socket用法及代碼示例
- Node.js assert.notEqual(actual, expected[, message])用法及代碼示例
- Node.js tlsSocket.authorized用法及代碼示例
- Node.js zlib.deflateRaw()用法及代碼示例
- Node.js http.IncomingMessage message.rawHeaders用法及代碼示例
- Node.js Console用法及代碼示例
- Node.js GM transparent()用法及代碼示例
- Node.js URL.protocol用法及代碼示例
- Node.js http.Agent.reuseSocket(socket, request)用法及代碼示例
- Node.js fs.filehandle.datasync()用法及代碼示例
- Node.js socket.bind()用法及代碼示例
- Node.js v8.getHeapSpaceStatistics()用法及代碼示例
- Node.js http2session.destroyed用法及代碼示例
- Node.js http.ServerResponse response.statusCode用法及代碼示例
- Node.js Buffer buf.writeBigUInt64BE(value[, offset])用法及代碼示例
- Node.js Http2ServerResponse.finished用法及代碼示例
- Node.js Http2Stream close用法及代碼示例
注:本文由純淨天空篩選整理自nodejs.org大神的英文原創作品 ServerHttp2Session.altsvc(alt, originOrStream)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。