@@ -27,7 +27,7 @@ const {
27
27
Symbol
28
28
} = primordials ;
29
29
30
- const { Readable , finished } = require ( 'stream' ) ;
30
+ const Stream = require ( 'stream' ) ;
31
31
32
32
const kHeaders = Symbol ( 'kHeaders' ) ;
33
33
const kHeadersCount = Symbol ( 'kHeadersCount' ) ;
@@ -54,7 +54,7 @@ function IncomingMessage(socket) {
54
54
} ;
55
55
}
56
56
57
- Readable . call ( this , streamOptions ) ;
57
+ Stream . Readable . call ( this , { autoDestroy : false , ... streamOptions } ) ;
58
58
59
59
this . _readableState . readingMore = true ;
60
60
@@ -89,8 +89,8 @@ function IncomingMessage(socket) {
89
89
// read by the user, so there's no point continuing to handle it.
90
90
this . _dumped = false ;
91
91
}
92
- ObjectSetPrototypeOf ( IncomingMessage . prototype , Readable . prototype ) ;
93
- ObjectSetPrototypeOf ( IncomingMessage , Readable ) ;
92
+ ObjectSetPrototypeOf ( IncomingMessage . prototype , Stream . Readable . prototype ) ;
93
+ ObjectSetPrototypeOf ( IncomingMessage , Stream . Readable ) ;
94
94
95
95
ObjectDefineProperty ( IncomingMessage . prototype , 'connection' , {
96
96
get : function ( ) {
@@ -160,31 +160,19 @@ IncomingMessage.prototype._read = function _read(n) {
160
160
readStart ( this . socket ) ;
161
161
} ;
162
162
163
+
163
164
// It's possible that the socket will be destroyed, and removed from
164
165
// any messages, before ever calling this. In that case, just skip
165
166
// it, since something else is destroying this connection anyway.
166
- IncomingMessage . prototype . _destroy = function _destroy ( err , cb ) {
167
- if ( ! this . readableEnded || ! this . complete ) {
168
- this . aborted = true ;
169
- this . emit ( 'aborted' ) ;
170
- }
171
-
172
- // If aborted and the underlying socket is not already destroyed,
173
- // destroy it.
174
- // We have to check if the socket is already destroyed because finished
175
- // does not call the callback when this methdod is invoked from `_http_client`
176
- // in `test/parallel/test-http-client-spurious-aborted.js`
177
- if ( this . socket && ! this . socket . destroyed && this . aborted ) {
178
- this . socket . destroy ( err ) ;
179
- const cleanup = finished ( this . socket , ( e ) => {
180
- cleanup ( ) ;
181
- onError ( this , e || err , cb ) ;
182
- } ) ;
183
- } else {
184
- onError ( this , err , cb ) ;
185
- }
167
+ IncomingMessage . prototype . destroy = function destroy ( error ) {
168
+ // TODO(ronag): Implement in terms of _destroy
169
+ this . destroyed = true ;
170
+ if ( this . socket )
171
+ this . socket . destroy ( error ) ;
172
+ return this ;
186
173
} ;
187
174
175
+
188
176
IncomingMessage . prototype . _addHeaderLines = _addHeaderLines ;
189
177
function _addHeaderLines ( headers , n ) {
190
178
if ( headers && headers . length ) {
@@ -361,16 +349,6 @@ IncomingMessage.prototype._dump = function _dump() {
361
349
}
362
350
} ;
363
351
364
- function onError ( self , error , cb ) {
365
- // This is to keep backward compatible behavior.
366
- // An error is emitted only if there are listeners attached to the event.
367
- if ( self . listenerCount ( 'error' ) === 0 ) {
368
- cb ( ) ;
369
- } else {
370
- cb ( error ) ;
371
- }
372
- }
373
-
374
352
module . exports = {
375
353
IncomingMessage,
376
354
readStart,
0 commit comments