@@ -29,12 +29,15 @@ const {
2929
3030const { Readable, finished } = require ( 'stream' ) ;
3131
32+ const { AbortController } = require ( 'internal/abort_controller' ) ;
33+
3234const kHeaders = Symbol ( 'kHeaders' ) ;
3335const kHeadersDistinct = Symbol ( 'kHeadersDistinct' ) ;
3436const kHeadersCount = Symbol ( 'kHeadersCount' ) ;
3537const kTrailers = Symbol ( 'kTrailers' ) ;
3638const kTrailersDistinct = Symbol ( 'kTrailersDistinct' ) ;
3739const kTrailersCount = Symbol ( 'kTrailersCount' ) ;
40+ const kAbortController = Symbol ( 'kAbortController' ) ;
3841
3942function readStart ( socket ) {
4043 if ( socket && ! socket . _paused && socket . readable )
@@ -90,6 +93,7 @@ function IncomingMessage(socket) {
9093 // Flag for when we decide that this message cannot possibly be
9194 // read by the user, so there's no point continuing to handle it.
9295 this . _dumped = false ;
96+ this [ kAbortController ] = undefined ;
9397}
9498ObjectSetPrototypeOf ( IncomingMessage . prototype , Readable . prototype ) ;
9599ObjectSetPrototypeOf ( IncomingMessage , Readable ) ;
@@ -184,6 +188,28 @@ ObjectDefineProperty(IncomingMessage.prototype, 'trailersDistinct', {
184188 } ,
185189} ) ;
186190
191+ ObjectDefineProperty ( IncomingMessage . prototype , 'signal' , {
192+ __proto__ : null ,
193+ configurable : true ,
194+ get : function ( ) {
195+ if ( this [ kAbortController ] === undefined ) {
196+ const ac = new AbortController ( ) ;
197+ this [ kAbortController ] = ac ;
198+ if ( this . destroyed ) {
199+ ac . abort ( ) ;
200+ } else {
201+ this . once ( 'close' , function ( ) {
202+ ac . abort ( ) ;
203+ } ) ;
204+ this . once ( 'abort' , function ( ) {
205+ ac . abort ( ) ;
206+ } ) ;
207+ }
208+ }
209+ return this [ kAbortController ] . signal ;
210+ } ,
211+ } ) ;
212+
187213IncomingMessage . prototype . setTimeout = function setTimeout ( msecs , callback ) {
188214 if ( callback )
189215 this . on ( 'timeout' , callback ) ;
0 commit comments