Skip to content

Commit b10a601

Browse files
committed
fixup
1 parent 607439b commit b10a601

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-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

+22-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,23 @@ 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.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+
364383
function 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
};

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)