阿西河

所有教程

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

我的收藏

    最近访问  (文章)

      教程列表

      抓包专区
      测试专区

      Node.js http2stream.respond

      Node.js http2stream.respond([headers[, options]])

      新增于: v8.4.0

      • headers < HTTP/2 Headers Object>
      • options < Object>
        • endStream < boolean> Set to true to indicate that the response will not include payload data.
        • waitForTrailers < boolean> When true, the Http2Stream will emit the ‘wantTrailers’ event after the final DATA frame has been sent.
      const http2 = require('http2');
      const server = http2.createServer();
      server.on('stream', (stream) => {
        stream.respond({ ':status': 200 });
        stream.end('some data');
      });
      
      

      When the options.waitForTrailers option is set, the ‘wantTrailers’ event will be emitted immediately after queuing the last chunk of payload data to be sent. The http2stream.sendTrailers() method can then be used to sent trailing header fields to the peer.

      When options.waitForTrailers is set, the Http2Stream will not automatically close when the final DATA frame is transmitted. User code must call either http2stream.sendTrailers() or http2stream.close() to close the Http2Stream.

      const http2 = require('http2');
      const server = http2.createServer();
      server.on('stream', (stream) => {
        stream.respond({ ':status': 200 }, { waitForTrailers: true });
        stream.on('wantTrailers', () => {
          stream.sendTrailers({ ABC: 'some value to send' });
        });
        stream.end('some data');
      });
      

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


      目录
      本文目录
      目录