Take this sample code:
const h2 = require('http2');
const server = h2.createServer();
server.on('stream', (stream) => {
stream.session.destroy();
});
server.listen(0, () => {
const client = h2.connect(`http://localhost:${server.address().port}`);
client.on('close', () => {
server.close();;
});
const clientStream = client.request();
clientStream.on('aborted', () => {
// Never called
console.log('aborted');
});
clientStream.on('close', () => {
// `rstCode === 8 (NGHTTP2_CANCEL)
console.log('close', clientStream.rstCode);
});
clientStream.on('error', (err) => {
// Never called
throw err;
});
});
in which clientStream is aborted before any response is generated via the stream.session.destroy() call. I would expect in this case clientStream to emit an error, but by looking at the code, this specific case is explicitly not reporting the error because:
// RST code 8 not emitted as an error as its used by clients to signify
// abort and is already covered by aborted event, also allows more
// seamless compatibility with http1
but, as demonstrated in the example, the aborted event is not reported. I don't know exactly what the http1 compatibility means in this context.
Also, if we look at the documentation of the Http2Stream close event, it seems to contradict the following statement:
The HTTP/2 error code used when closing the stream can be retrieved using the http2stream.rstCode property. If the code is any value other than NGHTTP2_NO_ERROR (0), an 'error' event will have also been emitted.
Any thoughts whether this is a bug in the code, the documentation, both?.
Thanks!
Take this sample code:
in which
clientStreamis aborted before any response is generated via thestream.session.destroy()call. I would expect in this caseclientStreamto emit anerror, but by looking at the code, this specific case is explicitly not reporting the error because:but, as demonstrated in the example, the
abortedevent is not reported. I don't know exactly what the http1 compatibility means in this context.Also, if we look at the documentation of the
Http2Streamcloseevent, it seems to contradict the following statement:Any thoughts whether this is a bug in the code, the documentation, both?.
Thanks!