• 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.
    1. const http2 = require('http2');
    2. const server = http2.createServer();
    3. server.on('stream', (stream) => {
    4. stream.respond({ ':status': 200 });
    5. stream.end('some data');
    6. });

    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.

    1. const http2 = require('http2');
    2. const server = http2.createServer();
    3. server.on('stream', (stream) => {
    4. stream.respond({ ':status': 200 }, { waitForTrailers: true });
    5. stream.on('wantTrailers', () => {
    6. stream.sendTrailers({ ABC: 'some value to send' });
    7. });
    8. stream.end('some data');
    9. });