Skip to content

Commit 9c3739d

Browse files
committed
fixup: isServerRequest
1 parent 17af147 commit 9c3739d

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

lib/_http_client.js

-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ const {
5353
prepareError,
5454
} = require('_http_common');
5555
const { OutgoingMessage } = require('_http_outgoing');
56-
const { kDestroy } = require('internal/streams/destroy');
5756
const Agent = require('_http_agent');
5857
const { Buffer } = require('buffer');
5958
const { defaultTriggerAsyncIdScope } = require('internal/async_hooks');
@@ -610,7 +609,6 @@ function parserOnIncomingClient(res, shouldKeepAlive) {
610609
DTRACE_HTTP_CLIENT_RESPONSE(socket, req);
611610
req.res = res;
612611
res.req = req;
613-
res[kDestroy] = null;
614612

615613
// Add our listener first, so that we guarantee socket cleanup
616614
res.on('end', responseOnEnd);

lib/_http_incoming.js

-6
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ const {
3131
} = primordials;
3232

3333
const { Readable, finished } = require('stream');
34-
const { kDestroy } = require('internal/streams/destroy');
3534

3635
const kHeaders = Symbol('kHeaders');
3736
const kHeadersCount = Symbol('kHeadersCount');
@@ -199,11 +198,6 @@ IncomingMessage.prototype._destroy = function _destroy(err, cb) {
199198
}
200199
};
201200

202-
IncomingMessage.prototype[kDestroy] = function(err) {
203-
this.socket = null;
204-
this.destroy(err);
205-
};
206-
207201
IncomingMessage.prototype._addHeaderLines = _addHeaderLines;
208202
function _addHeaderLines(headers, n) {
209203
if (headers && headers.length) {

lib/internal/streams/destroy.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const {
1414
kDestroyed,
1515
isDestroyed,
1616
isFinished,
17+
isServerRequest
1718
} = require('internal/streams/utils');
1819

1920
const kDestroy = Symbol('kDestroy');
@@ -389,8 +390,9 @@ function destroyer(stream, err) {
389390
}
390391

391392
// TODO: Remove isRequest branches.
392-
if (typeof stream[kDestroy] === 'function') {
393-
stream[kDestroy](err);
393+
if (isServerRequest(stream)) {
394+
stream.socket = null;
395+
stream.destroy(err);
394396
} else if (isRequest(stream)) {
395397
stream.abort();
396398
} else if (isRequest(stream.req)) {
@@ -412,7 +414,6 @@ function destroyer(stream, err) {
412414
}
413415

414416
module.exports = {
415-
kDestroy,
416417
construct,
417418
destroyer,
418419
destroy,

lib/internal/streams/utils.js

+10
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,14 @@ function isServerResponse(stream) {
164164
);
165165
}
166166

167+
function isServerRequest(stream) {
168+
return (
169+
typeof stream._consuming === 'boolean' &&
170+
typeof stream._dumped === 'boolean' &&
171+
stream.upgradeOrConnect === undefined
172+
);
173+
}
174+
167175
function willEmitClose(stream) {
168176
if (!isStream(stream)) return null;
169177

@@ -194,5 +202,7 @@ module.exports = {
194202
isWritableStream,
195203
isWritableEnded,
196204
isWritableFinished,
205+
isServerRequest,
206+
isServerResponse,
197207
willEmitClose,
198208
};

0 commit comments

Comments
 (0)