阿西河

所有教程

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

我的收藏

    最近访问  (文章)

      教程列表

      抓包专区
      测试专区

      Node.js http2 扩展的 CONNECT 协议

      Node.js http2 扩展的 CONNECT 协议

      RFC 8441 defines an “Extended CONNECT Protocol” extension to HTTP/2 that may be used to bootstrap the use of an Http2Stream using the CONNECT method as a tunnel for other communication protocols (such as WebSockets).

      The use of the Extended CONNECT Protocol is enabled by HTTP/2 servers by using the enableConnectProtocol setting:

      const http2 = require('http2');
      const settings = { enableConnectProtocol: true };
      const server = http2.createServer({ settings });
      
      

      Once the client receives the SETTINGS frame from the server indicating that the extended CONNECT may be used, it may send CONNECT requests that use the ‘:protocol’ HTTP/2 pseudo-header:

      const http2 = require('http2');
      const client = http2.connect('http://localhost:8080');
      client.on('remoteSettings', (settings) => {
        if (settings.enableConnectProtocol) {
          const req = client.request({ ':method': 'CONNECT', ':protocol': 'foo' });
          // ...
        }
      });
      

      更多内容请参考:Node.js HTTP2,或者通过 点击对应菜单 进行查看;


      目录
      本文目录
      目录