2424const {
2525 ArrayIsArray,
2626 Boolean,
27+ DateNow,
2728 Error,
2829 FunctionPrototypeCall,
2930 NumberIsFinite,
@@ -70,6 +71,7 @@ const {
7071 isTraceHTTPEnabled,
7172 traceBegin,
7273 traceEnd,
74+ getNextInspectorEventId,
7375 getNextTraceEventId,
7476} = require ( 'internal/http' ) ;
7577const {
@@ -93,6 +95,14 @@ const {
9395 stopPerf,
9496} = require ( 'internal/perf/observe' ) ;
9597
98+ const {
99+ isEnabled : isInspectorEnabled ,
100+ requestWillBeSent,
101+ responseReceived,
102+ dataReceived,
103+ loadingFinished,
104+ } = internalBinding ( 'inspector' ) ;
105+
96106const kClientRequestStatistics = Symbol ( 'ClientRequestStatistics' ) ;
97107
98108const dc = require ( 'diagnostics_channel' ) ;
@@ -375,14 +385,15 @@ ObjectSetPrototypeOf(ClientRequest, OutgoingMessage);
375385
376386ClientRequest . prototype . _finish = function _finish ( ) {
377387 FunctionPrototypeCall ( OutgoingMessage . prototype . _finish , this ) ;
388+ const url = `${ this . protocol } //${ this . host } ${ this . path } ` ;
378389 if ( hasObserver ( 'http' ) ) {
379390 startPerf ( this , kClientRequestStatistics , {
380391 type : 'http' ,
381392 name : 'HttpClient' ,
382393 detail : {
383394 req : {
384395 method : this . method ,
385- url : ` ${ this . protocol } // ${ this . host } ${ this . path } ` ,
396+ url,
386397 headers : typeof this . getHeaders === 'function' ? this . getHeaders ( ) : { } ,
387398 } ,
388399 } ,
@@ -393,6 +404,14 @@ ClientRequest.prototype._finish = function _finish() {
393404 request : this ,
394405 } ) ;
395406 }
407+
408+ if ( isInspectorEnabled ( ) ) {
409+ this . _inspectorEventId = getNextInspectorEventId ( ) ;
410+ const wallTime = DateNow ( ) ;
411+ const timestamp = wallTime / 1000 ;
412+ requestWillBeSent ( this . _inspectorEventId , url , this . method , timestamp , wallTime ) ;
413+ }
414+
396415 if ( isTraceHTTPEnabled ( ) ) {
397416 this . _traceEventId = getNextTraceEventId ( ) ;
398417 traceBegin ( HTTP_CLIENT_TRACE_EVENT_NAME , this . _traceEventId ) ;
@@ -680,6 +699,21 @@ function parserOnIncomingClient(res, shouldKeepAlive) {
680699 response : res ,
681700 } ) ;
682701 }
702+
703+ if ( isInspectorEnabled ( ) && typeof req . _inspectorEventId === 'string' ) {
704+ responseReceived ( req . _inspectorEventId , DateNow ( ) / 1000 ) ;
705+ let response = '' ;
706+ const onData = ( chunk ) => {
707+ dataReceived ( req . _inspectorEventId , DateNow ( ) / 1000 , chunk . length ) ;
708+ response += chunk . toString ( ) ;
709+ } ;
710+ res . on ( 'data' , onData ) ;
711+ res . on ( 'end' , ( ) => {
712+ loadingFinished ( req . _inspectorEventId , response , DateNow ( ) / 1000 , response . length ) ;
713+ res . removeListener ( 'data' , onData ) ;
714+ } ) ;
715+ }
716+
683717 if ( isTraceHTTPEnabled ( ) && typeof req . _traceEventId === 'number' ) {
684718 traceEnd ( HTTP_CLIENT_TRACE_EVENT_NAME , req . _traceEventId , {
685719 path : req . path ,
0 commit comments