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)。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。