nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
107.84k stars 29.72k forks source link

Add a `stream` event for client-side HTTP2 sessions #34264

Open szmarczak opened 4 years ago

szmarczak commented 4 years ago

Is your feature request related to a problem? Please describe.

const http2 = require('http2');
const session = http2.connect('https://google.com');

// Unfortunately there is no API for this.
// It would be very useful for example to catch how many streams are pending in this session.
session.once('stream', stream => {
    console.log('Got stream!');
});

const request = session.request();

session.destroy();

Describe the solution you'd like Introduce a new stream event to HTTP2 client-side sessions, which is emitted on new requests. Push streams could be emitted e.g. via pushStream.

Describe alternatives you've considered None.

rickyes commented 4 years ago

Refs: https://nodejs.org/dist/latest-v14.x/docs/api/http2.html#http2_push_streams_on_the_client

jasnell commented 4 years ago

The 'stream' event is already supported for http2 client sessions.

szmarczak commented 4 years ago

Ah sorry, I meant request streams, not the push ones.