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