@@ -187,6 +187,18 @@ const { UV_EOF } = internalBinding('uv');
187
187
188
188
const { StreamPipe } = internalBinding ( 'stream_pipe' ) ;
189
189
const { _connectionListener : httpConnectionListener } = http ;
190
+
191
+ const dc = require ( 'diagnostics_channel' ) ;
192
+ const onClientStreamCreatedChannel = dc . channel ( 'http2.client.stream.created' ) ;
193
+ const onClientStreamStartChannel = dc . channel ( 'http2.client.stream.start' ) ;
194
+ const onClientStreamErrorChannel = dc . channel ( 'http2.client.stream.error' ) ;
195
+ const onClientStreamFinishChannel = dc . channel ( 'http2.client.stream.finish' ) ;
196
+ const onClientStreamCloseChannel = dc . channel ( 'http2.client.stream.close' ) ;
197
+ const onServerStreamStartChannel = dc . channel ( 'http2.server.stream.start' ) ;
198
+ const onServerStreamErrorChannel = dc . channel ( 'http2.server.stream.error' ) ;
199
+ const onServerStreamFinishChannel = dc . channel ( 'http2.server.stream.finish' ) ;
200
+ const onServerStreamCloseChannel = dc . channel ( 'http2.server.stream.close' ) ;
201
+
190
202
let debug = require ( 'internal/util/debuglog' ) . debuglog ( 'http2' , ( fn ) => {
191
203
debug = fn ;
192
204
} ) ;
@@ -375,9 +387,23 @@ function onSessionHeaders(handle, id, cat, flags, headers, sensitiveHeaders) {
375
387
stream . end ( ) ;
376
388
stream [ kState ] . flags |= STREAM_FLAGS_HEAD_REQUEST ;
377
389
}
390
+
391
+ if ( onServerStreamStartChannel . hasSubscribers ) {
392
+ onServerStreamStartChannel . publish ( {
393
+ stream,
394
+ headers : obj ,
395
+ } ) ;
396
+ }
378
397
} else {
379
398
// eslint-disable-next-line no-use-before-define
380
399
stream = new ClientHttp2Stream ( session , handle , id , { } ) ;
400
+ if ( onClientStreamCreatedChannel . hasSubscribers ) {
401
+ onClientStreamCreatedChannel . publish ( {
402
+ stream,
403
+ headers : obj ,
404
+ } ) ;
405
+ }
406
+
381
407
if ( endOfStream ) {
382
408
stream . push ( null ) ;
383
409
}
@@ -416,6 +442,16 @@ function onSessionHeaders(handle, id, cat, flags, headers, sensitiveHeaders) {
416
442
reqAsync . runInAsyncScope ( process . nextTick , null , emit , stream , event , obj , flags , headers ) ;
417
443
else
418
444
process . nextTick ( emit , stream , event , obj , flags , headers ) ;
445
+
446
+ if ( event === 'response' ) {
447
+ if ( onClientStreamFinishChannel . hasSubscribers ) {
448
+ onClientStreamFinishChannel . publish ( {
449
+ stream,
450
+ headers : obj ,
451
+ flags,
452
+ } ) ;
453
+ }
454
+ }
419
455
}
420
456
if ( endOfStream ) {
421
457
stream . push ( null ) ;
@@ -766,7 +802,14 @@ function requestOnConnect(headers, options) {
766
802
}
767
803
return ;
768
804
}
805
+
769
806
this [ kInit ] ( ret . id ( ) , ret ) ;
807
+ if ( onClientStreamStartChannel . hasSubscribers ) {
808
+ onClientStreamStartChannel . publish ( {
809
+ stream : this ,
810
+ headers : this [ kSentHeaders ] ,
811
+ } ) ;
812
+ }
770
813
}
771
814
772
815
// Validates that priority options are correct, specifically:
@@ -1851,6 +1894,14 @@ class ClientHttp2Session extends Http2Session {
1851
1894
} else {
1852
1895
onConnect ( ) ;
1853
1896
}
1897
+
1898
+ if ( onClientStreamCreatedChannel . hasSubscribers ) {
1899
+ onClientStreamCreatedChannel . publish ( {
1900
+ stream,
1901
+ headers,
1902
+ } ) ;
1903
+ }
1904
+
1854
1905
return stream ;
1855
1906
}
1856
1907
}
@@ -1925,6 +1976,7 @@ const kSubmitRstStream = 1;
1925
1976
const kForceRstStream = 2 ;
1926
1977
1927
1978
function closeStream ( stream , code , rstStreamStatus = kSubmitRstStream ) {
1979
+ const type = stream . session [ kType ] ;
1928
1980
const state = stream [ kState ] ;
1929
1981
state . flags |= STREAM_FLAGS_CLOSED ;
1930
1982
state . rstCode = code ;
@@ -1955,6 +2007,20 @@ function closeStream(stream, code, rstStreamStatus = kSubmitRstStream) {
1955
2007
else
1956
2008
stream . once ( 'finish' , finishFn ) ;
1957
2009
}
2010
+
2011
+ if ( type === NGHTTP2_SESSION_CLIENT ) {
2012
+ if ( onClientStreamCloseChannel . hasSubscribers ) {
2013
+ onClientStreamCloseChannel . publish ( {
2014
+ stream,
2015
+ code,
2016
+ } ) ;
2017
+ }
2018
+ } else if ( onServerStreamCloseChannel . hasSubscribers ) {
2019
+ onServerStreamCloseChannel . publish ( {
2020
+ stream,
2021
+ code,
2022
+ } ) ;
2023
+ }
1958
2024
}
1959
2025
1960
2026
function finishCloseStream ( code ) {
@@ -2381,6 +2447,21 @@ class Http2Stream extends Duplex {
2381
2447
setImmediate ( ( ) => {
2382
2448
session [ kMaybeDestroy ] ( ) ;
2383
2449
} ) ;
2450
+ if ( err ) {
2451
+ if ( session [ kType ] === NGHTTP2_SESSION_CLIENT ) {
2452
+ if ( onClientStreamErrorChannel . hasSubscribers ) {
2453
+ onClientStreamErrorChannel . publish ( {
2454
+ stream : this ,
2455
+ error : err ,
2456
+ } ) ;
2457
+ }
2458
+ } else if ( onServerStreamErrorChannel . hasSubscribers ) {
2459
+ onServerStreamErrorChannel . publish ( {
2460
+ stream : this ,
2461
+ error : err ,
2462
+ } ) ;
2463
+ }
2464
+ }
2384
2465
callback ( err ) ;
2385
2466
}
2386
2467
// The Http2Stream can be destroyed if it has closed and if the readable
@@ -2766,6 +2847,13 @@ class ServerHttp2Stream extends Http2Stream {
2766
2847
stream [ kState ] . flags |= STREAM_FLAGS_HEAD_REQUEST ;
2767
2848
2768
2849
process . nextTick ( callback , null , stream , headers , 0 ) ;
2850
+
2851
+ if ( onServerStreamStartChannel . hasSubscribers ) {
2852
+ onServerStreamStartChannel . publish ( {
2853
+ stream,
2854
+ headers,
2855
+ } ) ;
2856
+ }
2769
2857
}
2770
2858
2771
2859
// Initiate a response on this Http2Stream
@@ -2813,8 +2901,14 @@ class ServerHttp2Stream extends Http2Stream {
2813
2901
}
2814
2902
2815
2903
const ret = this [ kHandle ] . respond ( headersList , streamOptions ) ;
2816
- if ( ret < 0 )
2904
+ if ( ret < 0 ) {
2817
2905
this . destroy ( new NghttpError ( ret ) ) ;
2906
+ } else if ( onServerStreamFinishChannel . hasSubscribers ) {
2907
+ onServerStreamFinishChannel . publish ( {
2908
+ stream : this ,
2909
+ headers,
2910
+ } ) ;
2911
+ }
2818
2912
}
2819
2913
2820
2914
// Initiate a response using an open FD. Note that there are fewer
0 commit comments