serverhttp2session.altsvc(alt, originOrStream)
-
alt
<string> RFC 7838 定义的替代服务配置的描述。¥
alt
<string> A description of the alternative service configuration as defined by RFC 7838. -
originOrStream
<number> | <string> | <URL> | <Object> 指定来源的 URL 字符串(或具有origin
属性的Object
)或由http2stream.id
属性给出的活动Http2Stream
的数字标识符。¥
originOrStream
<number> | <string> | <URL> | <Object> Either a URL string specifying the origin (or anObject
with anorigin
property) or the numeric identifier of an activeHttp2Stream
as given by thehttp2stream.id
property.
向连接的客户端提交 ALTSVC
帧(由 RFC 7838 定义)。
¥Submits an ALTSVC
frame (as defined by RFC 7838) to the connected client.
import { createServer } from 'node:http2';
const server = 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);
});
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
的来源相关联。
¥Sending an ALTSVC
frame with a specific stream ID indicates that the alternate
service is associated with the origin of the given Http2Stream
.
alt
和原始字符串必须仅包含 ASCII 字节,并被严格解释为 ASCII 字节序列。可以传入特殊值 'clear'
以清除给定域的任何先前设置的替代服务。
¥The alt
and origin string must contain only ASCII bytes and are
strictly interpreted as a sequence of ASCII bytes. The special value 'clear'
may be passed to clear any previously set alternative service for a given
domain.
当为 originOrStream
参数传入字符串时,则它将被解析为 URL 并导出来源。例如,HTTP URL 'https://example.org/foo/bar'
的来源是 ASCII 字符串 'https://example.org'
。如果给定的字符串无法解析为 URL,或者无法导出有效的来源,则会抛出错误。
¥When a string is passed for the originOrStream
argument, it will be parsed as
a URL and the origin will be derived. For instance, the origin for the
HTTP URL 'https://example.org/foo/bar'
is the ASCII string
'https://example.org'
. An error will be thrown if either the given string
cannot be parsed as a URL or if a valid origin cannot be derived.
URL
对象,或任何具有 origin
属性的对象,都可以作为 originOrStream
传入,在这种情况下,将使用 origin
属性的值。origin
属性的值必须是正确序列化的 ASCII 来源。
¥A URL
object, or any object with an origin
property, may be passed as
originOrStream
, in which case the value of the origin
property will be
used. The value of the origin
property must be a properly serialized
ASCII origin.