Skip to content

Commit

Permalink
fixup: isServerRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Jul 7, 2021
1 parent 17af147 commit fb49c78
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
2 changes: 0 additions & 2 deletions lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ const {
prepareError,
} = require('_http_common');
const { OutgoingMessage } = require('_http_outgoing');
const { kDestroy } = require('internal/streams/destroy');
const Agent = require('_http_agent');
const { Buffer } = require('buffer');
const { defaultTriggerAsyncIdScope } = require('internal/async_hooks');
Expand Down Expand Up @@ -610,7 +609,6 @@ function parserOnIncomingClient(res, shouldKeepAlive) {
DTRACE_HTTP_CLIENT_RESPONSE(socket, req);
req.res = res;
res.req = req;
res[kDestroy] = null;

// Add our listener first, so that we guarantee socket cleanup
res.on('end', responseOnEnd);
Expand Down
6 changes: 0 additions & 6 deletions lib/_http_incoming.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const {
} = primordials;

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

const kHeaders = Symbol('kHeaders');
const kHeadersCount = Symbol('kHeadersCount');
Expand Down Expand Up @@ -199,11 +198,6 @@ IncomingMessage.prototype._destroy = function _destroy(err, cb) {
}
};

IncomingMessage.prototype[kDestroy] = function(err) {
this.socket = null;
this.destroy(err);
};

IncomingMessage.prototype._addHeaderLines = _addHeaderLines;
function _addHeaderLines(headers, n) {
if (headers && headers.length) {
Expand Down
7 changes: 4 additions & 3 deletions lib/internal/streams/destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const {
kDestroyed,
isDestroyed,
isFinished,
isServerRequest
} = require('internal/streams/utils');

const kDestroy = Symbol('kDestroy');
Expand Down Expand Up @@ -389,8 +390,9 @@ function destroyer(stream, err) {
}

// TODO: Remove isRequest branches.
if (typeof stream[kDestroy] === 'function') {
stream[kDestroy](err);
if (isServerRequest(stream)) {
stream.socket = null;
stream.destroy(err);
} else if (isRequest(stream)) {
stream.abort();
} else if (isRequest(stream.req)) {
Expand All @@ -412,7 +414,6 @@ function destroyer(stream, err) {
}

module.exports = {
kDestroy,
construct,
destroyer,
destroy,
Expand Down
10 changes: 10 additions & 0 deletions lib/internal/streams/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@ function isServerResponse(stream) {
);
}

function isServerRequest(stream) {
return (
typeof stream._consuming === 'boolean' &&
typeof stream._dumped === 'boolean' &&
stream.req?.upgradeOrConnect === undefined
);
}

function willEmitClose(stream) {
if (!isStream(stream)) return null;

Expand Down Expand Up @@ -194,5 +202,7 @@ module.exports = {
isWritableStream,
isWritableEnded,
isWritableFinished,
isServerRequest,
isServerResponse,
willEmitClose,
};

0 comments on commit fb49c78

Please sign in to comment.