Skip to content

Commit 8979e0d

Browse files
jasnellMylesBorins
authored andcommitted
http2: use 'close' event instead of 'streamClosed'
PR-URL: #17328Fixes: #15303 Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Sebastiaan Deckers <[email protected]>
1 parent 7ceccb1 commit 8979e0d

25 files changed

+45
-47
lines changed

‎doc/api/http2.md‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ All [`Http2Stream`][] instances are destroyed either when:
631631
When an `Http2Stream` instance is destroyed, an attempt will be made to send an
632632
`RST_STREAM` frame will be sent to the connected peer.
633633

634-
Once the `Http2Stream` instance is destroyed, the `'streamClosed'` event will
634+
When the `Http2Stream` instance is destroyed, the `'close'` event will
635635
be emitted. Because `Http2Stream` is an instance of `stream.Duplex`, the
636636
`'end'` event will also be emitted if the stream data is currently flowing.
637637
The `'error'` event may also be emitted if `http2stream.destroy()` was called
@@ -653,6 +653,18 @@ abnormally aborted in mid-communication.
653653
*Note*: The `'aborted'` event will only be emitted if the `Http2Stream`
654654
writable side has not been ended.
655655

656+
#### Event: 'close'
657+
<!-- YAML
658+
added: v8.4.0
659+
-->
660+
661+
The `'close'` event is emitted when the `Http2Stream` is destroyed. Once
662+
this event is emitted, the `Http2Stream` instance is no longer usable.
663+
664+
The listener callback is passed a single argument specifying the HTTP/2 error
665+
code specified when closing the stream. If the code is any value other than
666+
`NGHTTP2_NO_ERROR` (`0`), an `'error'` event will also be emitted.
667+
656668
#### Event: 'error'
657669
<!-- YAML
658670
added: v8.4.0
@@ -672,18 +684,6 @@ argument identifying the frame type, and an integer argument identifying the
672684
error code. The `Http2Stream` instance will be destroyed immediately after the
673685
`'frameError'` event is emitted.
674686

675-
#### Event: 'streamClosed'
676-
<!-- YAML
677-
added: v8.4.0
678-
-->
679-
680-
The `'streamClosed'` event is emitted when the `Http2Stream` is destroyed. Once
681-
this event is emitted, the `Http2Stream` instance is no longer usable.
682-
683-
The listener callback is passed a single argument specifying the HTTP/2 error
684-
code specified when closing the stream. If the code is any value other than
685-
`NGHTTP2_NO_ERROR` (`0`), an `'error'` event will also be emitted.
686-
687687
#### Event: 'timeout'
688688
<!-- YAML
689689
added: v8.4.0

‎lib/internal/http2/compat.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ class Http2ServerRequest extends Readable{
250250
stream.on('close',onStreamClosedRequest);
251251
stream.on('aborted',onStreamAbortedRequest);
252252
constonfinish=this[kFinish].bind(this);
253-
stream.on('streamClosed',onfinish);
253+
stream.on('close',onfinish);
254254
stream.on('finish',onfinish);
255255
this.on('pause',onRequestPause);
256256
this.on('resume',onRequestResume);
@@ -383,7 +383,7 @@ class Http2ServerResponse extends Stream{
383383
stream.on('close',onStreamClosedResponse);
384384
stream.on('aborted',onStreamAbortedResponse);
385385
constonfinish=this[kFinish].bind(this);
386-
stream.on('streamClosed',onfinish);
386+
stream.on('close',onfinish);
387387
stream.on('finish',onfinish);
388388
}
389389

‎lib/internal/http2/core.js‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,8 @@ function onStreamTrailers(){
224224
returnheadersList;
225225
}
226226

227-
// Called when the stream is closed. The streamClosed event is emitted on the
228-
// Http2Stream instance. Note that this event is distinctly different than the
229-
// require('stream') interface 'close' event which deals with the state of the
230-
// Readable and Writable sides of the Duplex.
227+
// Called when the stream is closed. The close event is emitted on the
228+
// Http2Stream instance
231229
functiononStreamClose(code){
232230
conststream=this[kOwner];
233231
stream[kUpdateTimer]();
@@ -1475,7 +1473,7 @@ function continueStreamDestroy(err, callback){
14751473
abort(this);
14761474
this.push(null);// Close the readable side
14771475
this.end();// Close the writable side
1478-
process.nextTick(emit,this,'streamClosed',code);
1476+
process.nextTick(emit,this,'close',code);
14791477
}
14801478

14811479
functionfinishStreamDestroy(){

‎test/parallel/test-http2-client-http1-server.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ server.listen(0, common.mustCall(() =>{
1313
constclient=http2.connect(`http://localhost:${server.address().port}`);
1414

1515
constreq=client.request();
16-
req.on('streamClosed',common.mustCall());
16+
req.on('close',common.mustCall());
1717

1818
client.on('error',common.expectsError({
1919
code: 'ERR_HTTP2_ERROR',

‎test/parallel/test-http2-client-rststream-before-connect.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ server.on('listening', common.mustCall(() =>{
2727
// second call doesn't do anything
2828
assert.doesNotThrow(()=>req.rstStream(8));
2929

30-
req.on('streamClosed',common.mustCall((code)=>{
30+
req.on('close',common.mustCall((code)=>{
3131
assert.strictEqual(req.destroyed,true);
3232
assert.strictEqual(code,0);
3333
server.close();

‎test/parallel/test-http2-client-stream-destroy-before-connect.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ server.on('listening', common.mustCall(() =>{
4141
})(err);
4242
}));
4343

44-
req.on('streamClosed',common.mustCall((code)=>{
44+
req.on('close',common.mustCall((code)=>{
4545
assert.strictEqual(req.rstCode,NGHTTP2_INTERNAL_ERROR);
4646
assert.strictEqual(code,NGHTTP2_INTERNAL_ERROR);
4747
server.close();

‎test/parallel/test-http2-client-unescaped-path.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ server.listen(0, common.mustCall(() =>{
3030
type: Error,
3131
message: 'Stream closed with error code 1'
3232
}));
33-
req.on('streamClosed',common.mustCall(maybeClose));
33+
req.on('close',common.mustCall(maybeClose));
3434
}
3535

3636
for(leti=0;i<=count;i+=1)

‎test/parallel/test-http2-compat-serverresponse-end.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,10 @@ const{
183183

184184

185185
{
186-
// Should be able to call .end with cb from stream 'streamClosed'
186+
// Should be able to call .end with cb from stream 'close'
187187
constserver=createServer(mustCall((request,response)=>{
188188
response.writeHead(HTTP_STATUS_OK,{foo: 'bar'});
189-
response.stream.on('streamClosed',mustCall(()=>{
189+
response.stream.on('close',mustCall(()=>{
190190
response.end(mustCall());
191191
}));
192192
}));

‎test/parallel/test-http2-compat-socket.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ server.on('request', common.mustCall(function(request, response){
6464
assert.strictEqual(request.socket.connecting,false);
6565

6666
// socket events are bound and emitted on Http2Stream
67-
request.socket.on('streamClosed',common.mustCall());
68-
request.socket.once('streamClosed',common.mustCall());
67+
request.socket.on('close',common.mustCall());
68+
request.socket.once('close',common.mustCall());
6969
request.socket.on('testEvent',common.mustCall());
7070
request.socket.emit('testEvent');
7171
}));

‎test/parallel/test-http2-multiheaders-raw.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ server.on('stream', common.mustCall((stream, headers, flags, rawHeaders) =>{
4242
server.listen(0,common.mustCall(()=>{
4343
constclient=http2.connect(`http://localhost:${server.address().port}`);
4444
constreq=client.request(src);
45-
req.on('streamClosed',common.mustCall(()=>{
45+
req.on('close',common.mustCall(()=>{
4646
server.close();
4747
client.destroy();
4848
}));

0 commit comments

Comments
(0)