阿西河

所有教程

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

我的收藏

    最近访问  (文章)

      教程列表

      抓包专区
      测试专区

      Node.js Http2Server stream 事件

      Node.js Http2Server stream 事件

      新增于: v8.4.0

      The ‘stream’ event is emitted when a ‘stream’ event has been emitted by an Http2Session associated with the server.

      const http2 = require('http2');
      const {
        HTTP2_HEADER_METHOD,
        HTTP2_HEADER_PATH,
        HTTP2_HEADER_STATUS,
        HTTP2_HEADER_CONTENT_TYPE
      } = http2.constants;
      
      const server = http2.createServer();
      server.on('stream', (stream, headers, flags) => {
        const method = headers[HTTP2_HEADER_METHOD];
        const path = headers[HTTP2_HEADER_PATH];
        // ...
        stream.respond({
          [HTTP2_HEADER_STATUS]: 200,
          [HTTP2_HEADER_CONTENT_TYPE]: 'text/plain'
        });
        stream.write('hello ');
        stream.end('world');
      });
      

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


      目录
      本文目录
      目录