Skip to content

Commit d27ee2a

Browse files
committed
fixup
1 parent 607439b commit d27ee2a

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

lib/_http_incoming.js

-9
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ const {
3333
} = primordials;
3434

3535
const { Readable, finished } = require('stream');
36-
const { kDestroy, destroy } = require('internal/stream')
3736

3837
const kHeaders = Symbol('kHeaders');
3938
const kHeadersCount = Symbol('kHeadersCount');
@@ -173,14 +172,6 @@ IncomingMessage.prototype._read = function _read(n) {
173172
readStart(this.socket);
174173
};
175174

176-
IncomingMessage.prototype[kDestroy] = function (err) {
177-
if (!err && !this.res.destroyed) {
178-
this.socket = null
179-
}
180-
181-
this.destroy(err)
182-
}
183-
184175
// It's possible that the socket will be destroyed, and removed from
185176
// any messages, before ever calling this. In that case, just skip
186177
// it, since something else is destroying this connection anyway.

lib/_http_server.js

+20-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ const {
6868
const { IncomingMessage } = require('_http_incoming');
6969
const {
7070
connResetException,
71-
codes
71+
codes,
72+
AbortError
7273
} = require('internal/errors');
74+
const { kDestroy } = require('internal/stream');
7375
const {
7476
ERR_HTTP_REQUEST_TIMEOUT,
7577
ERR_HTTP_HEADERS_SENT,
@@ -361,6 +363,21 @@ function writeHead(statusCode, reason, obj) {
361363
// Docs-only deprecated: DEP0063
362364
ServerResponse.prototype.writeHeader = ServerResponse.prototype.writeHead;
363365

366+
class ServerRequest extends IncomingMessage {
367+
[kDestroy] (err) {
368+
if (!this.readableEnded || !this.complete) {
369+
this.aborted = true;
370+
this.emit('aborted');
371+
}
372+
373+
if (!this.res.destroyed) {
374+
this._destroy = (err, cb) => cb(err);
375+
}
376+
377+
this.destroy(err);
378+
}
379+
}
380+
364381
function Server(options, requestListener) {
365382
if (!(this instanceof Server)) return new Server(options, requestListener);
366383

@@ -373,7 +390,7 @@ function Server(options, requestListener) {
373390
throw new ERR_INVALID_ARG_TYPE('options', 'object', options);
374391
}
375392

376-
this[kIncomingMessage] = options.IncomingMessage || IncomingMessage;
393+
this[kIncomingMessage] = options.IncomingMessage || ServerRequest;
377394
this[kServerResponse] = options.ServerResponse || ServerResponse;
378395

379396
const maxHeaderSize = options.maxHeaderSize;
@@ -997,6 +1014,7 @@ module.exports = {
9971014
STATUS_CODES,
9981015
Server,
9991016
ServerResponse,
1017+
ServerRequest,
10001018
_connectionListener: connectionListener,
10011019
kServerResponse
10021020
};

lib/internal/streams/destroy.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const {
55
codes: {
66
ERR_MULTIPLE_CALLBACK,
77
},
8+
AbortError,
89
} = require('internal/errors');
910
const {
1011
FunctionPrototypeCall,
@@ -374,8 +375,12 @@ function destroyer(stream, err) {
374375
return
375376
}
376377

378+
if (!err && (stream.readable || stream.writable)) {
379+
err = new AbortError();
380+
}
381+
377382
if (typeof stream[kDestroy] === 'function') {
378-
stream[kDestroy]();
383+
stream[kDestroy](err);
379384
} else if (isRequest(stream)) {
380385
stream.abort();
381386
} else if (isRequest(stream.req)) {
@@ -406,6 +411,7 @@ module.exports = {
406411
kDestroy,
407412
construct,
408413
destroyer,
414+
destroy2,
409415
destroy,
410416
undestroy,
411417
errorOrDestroy

0 commit comments

Comments
 (0)