serverhttp2session.origin(...origins)
添加于:v10.12.0
参数
向连接的客户端提交 ORIGIN
帧(由 RFC 8336 定义)以通告服务器能够提供权威响应的源集。
const http2 = require('node:http2');
const options = getSecureOptionsSomehow();
const server = http2.createSecureServer(options);
server.on('stream', (stream) => {
stream.respond();
stream.end('ok');
});
server.on('session', (session) => {
session.origin('https://example.com', 'https://example.org');
});
当字符串作为 origin
传递时,它将被解析为 URL 并派生源。例如,HTTP URL 'https://example.org/foo/bar'
的来源是 ASCII 字符串 'https://example.org'
。如果给定的字符串无法解析为 URL 或无法派生有效的来源,则会引发错误。
URL
对象或具有 origin
属性的任何对象都可以作为 origin
传递,在这种情况下,将使用 origin
属性的值。 origin
属性的值必须是正确序列化的 ASCII 源。
或者,当使用 http2.createSecureServer()
方法创建新的 HTTP/2 服务器时,可以使用 origins
选项:
const http2 = require('node:http2');
const options = getSecureOptionsSomehow();
options.origins = ['https://example.com', 'https://example.org'];
const server = http2.createSecureServer(options);
server.on('stream', (stream) => {
stream.respond();
stream.end('ok');
});
相关用法
- Node.js ServerHttp2Session.altsvc(alt, originOrStream)用法及代码示例
- 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.origin(...origins)。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。