阿西河

所有教程

公众号
🌙
阿西河前端的公众号

我的收藏

    最近访问  (文章)

      教程列表

      抓包专区
      测试专区

      Node.js 指定备选服务器

      Node.js 指定备选服务器

      The format of the alt parameter is strictly defined by RFC 7838 as an ASCII string containing a comma-delimited list of “alternative” protocols associated with a specific host and port.

      For example, the value ‘h2=“example.org:81”’ indicates that the HTTP/2 protocol is available on the host ‘example.org’ on TCP/IP port 81. The host and port must be contained within the quote (") characters.

      Multiple alternatives may be specified, for instance: ‘h2=“example.org:81”, h2=":82"’.

      The protocol identifier (‘h2’ in the examples) may be any valid ALPN Protocol ID.

      The syntax of these values is not validated by the Node.js implementation and are passed through as provided by the user or received from the peer.

      serverhttp2session.origin(…origins)

      新增于: v10.12.0

      • origins < string> | < URL> | < Object> One or more URL Strings passed as separate arguments.

      Submits an ORIGIN frame (as defined by RFC 8336) to the connected client to advertise the set of origins for which the server is capable of providing authoritative responses.

      const http2 = require('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');
      });
      

      When a string is passed as an origin, 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.

      A URL object, or any object with an origin property, may be passed as an origin, 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.

      Alternatively, the origins option may be used when creating a new HTTP/2 server using the http2.createSecureServer() method:

      const http2 = require('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 HTTP2,或者通过 点击对应菜单 进行查看;


      目录
      目录