阿西河

所有教程

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

我的收藏

    最近访问  (文章)

      教程列表

      抓包专区
      测试专区

      Node.js clienthttp2session.request

      Node.js clienthttp2session.request(headers[, options])

      新增于: v8.4.0

      • headers < HTTP/2 Headers Object>
      • options < Object>
        • endStream < boolean> true if the Http2Stream writable side should be closed initially, such as when sending a GET request that should not expect a payload body.
        • exclusive < boolean> When true and parent identifies a parent Stream, the created stream is made the sole direct dependency of the parent, with all other existing dependents made a dependent of the newly created stream. Default: false.
        • parent < number> Specifies the numeric identifier of a stream the newly created stream is dependent on.
        • weight < number> Specifies the relative dependency of a stream in relation to other streams with the same parent. The value is a number between 1 and 256 (inclusive).
        • waitForTrailers < boolean> When true, the Http2Stream will emit the ‘wantTrailers’ event after the final DATA frame has been sent.
      • Returns: < ClientHttp2Stream>

      For HTTP/2 Client Http2Session instances only, the http2session.request() creates and returns an Http2Stream instance that can be used to send an HTTP/2 request to the connected server.

      This method is only available if http2session.type is equal to http2.constants.NGHTTP2_SESSION_CLIENT.

      const http2 = require('http2');
      const clientSession = http2.connect('https://localhost:1234');
      const {
        HTTP2_HEADER_PATH,
        HTTP2_HEADER_STATUS
      } = http2.constants;
      
      const req = clientSession.request({ [HTTP2_HEADER_PATH]: '/' });
      req.on('response', (headers) => {
        console.log(headers[HTTP2_HEADER_STATUS]);
        req.on('data', (chunk) => { /* .. */ });
        req.on('end', () => { /* .. */ });
      });
      

      When the options.waitForTrailers option is set, the ‘wantTrailers’ event is emitted immediately after queuing the last chunk of payload data to be sent. The http2stream.sendTrailers() method can then be called to send trailing headers 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.

      The :method and :path pseudo-headers are not specified within headers, they respectively default to:

      :method = 'GET'
      :path = /
      

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


      目录
      本文目录
      目录