@@ -68,8 +68,10 @@ const {
6868const { IncomingMessage } = require ( '_http_incoming' ) ;
6969const {
7070 connResetException,
71- codes
71+ codes,
72+ AbortError
7273} = require ( 'internal/errors' ) ;
74+ const { kDestroy } = require ( 'internal/stream' ) ;
7375const {
7476 ERR_HTTP_REQUEST_TIMEOUT ,
7577 ERR_HTTP_HEADERS_SENT ,
@@ -361,6 +363,23 @@ function writeHead(statusCode, reason, obj) {
361363// Docs-only deprecated: DEP0063
362364ServerResponse . prototype . writeHeader = ServerResponse . prototype . writeHead ;
363365
366+ class ServerRequest extends IncomingMessage {
367+ [ kDestroy ] ( err ) {
368+ if ( ! this . res . destroyed ) {
369+ this . _destroy = ( err , cb ) => {
370+ if ( ! this . readableEnded || ! this . complete ) {
371+ this . aborted = true ;
372+ this . emit ( 'aborted' ) ;
373+ }
374+
375+ cb ( err )
376+ } ;
377+ }
378+
379+ this . destroy ( err ) ;
380+ }
381+ }
382+
364383function Server ( options , requestListener ) {
365384 if ( ! ( this instanceof Server ) ) return new Server ( options , requestListener ) ;
366385
@@ -373,7 +392,7 @@ function Server(options, requestListener) {
373392 throw new ERR_INVALID_ARG_TYPE ( 'options' , 'object' , options ) ;
374393 }
375394
376- this [ kIncomingMessage ] = options . IncomingMessage || IncomingMessage ;
395+ this [ kIncomingMessage ] = options . IncomingMessage || options . ServerRequest || ServerRequest ;
377396 this [ kServerResponse ] = options . ServerResponse || ServerResponse ;
378397
379398 const maxHeaderSize = options . maxHeaderSize ;
@@ -997,6 +1016,7 @@ module.exports = {
9971016 STATUS_CODES ,
9981017 Server,
9991018 ServerResponse,
1019+ ServerRequest,
10001020 _connectionListener : connectionListener ,
10011021 kServerResponse
10021022} ;
0 commit comments