From cd77811f8fd9aedf715bef7a41ed5afe6b87439c Mon Sep 17 00:00:00 2001 From: ZYSzys Date: Sun, 10 Mar 2019 00:06:48 +0800 Subject: [PATCH] http: reduce usage of public util PR-URL: https://github.com/nodejs/node/pull/26548 Refs: https://github.com/nodejs/node/issues/26546 Reviewed-By: Ruben Bridgewater Reviewed-By: James M Snell Reviewed-By: Colin Ihrig --- lib/_http_agent.js | 6 +++--- lib/_http_common.js | 2 +- lib/_http_outgoing.js | 4 ++-- lib/_http_server.js | 7 ++++--- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/_http_agent.js b/lib/_http_agent.js index 8632da45726514..15f6ecf77406da 100644 --- a/lib/_http_agent.js +++ b/lib/_http_agent.js @@ -22,9 +22,8 @@ 'use strict'; const net = require('net'); -const util = require('util'); const EventEmitter = require('events'); -const debug = util.debuglog('http'); +const debug = require('internal/util/debuglog').debuglog('http'); const { async_id_symbol } = require('internal/async_hooks').symbols; // New Agent code. @@ -106,7 +105,8 @@ function Agent(options) { }); } -util.inherits(Agent, EventEmitter); +Object.setPrototypeOf(Agent.prototype, EventEmitter.prototype); +Object.setPrototypeOf(Agent, EventEmitter); Agent.defaultMaxSockets = Infinity; diff --git a/lib/_http_common.js b/lib/_http_common.js index a83c82c9d4b292..bf885161571be1 100644 --- a/lib/_http_common.js +++ b/lib/_http_common.js @@ -36,7 +36,7 @@ const { readStop } = incoming; -const debug = require('util').debuglog('http'); +const debug = require('internal/util/debuglog').debuglog('http'); const kIncomingMessage = Symbol('IncomingMessage'); const kOnHeaders = HTTPParser.kOnHeaders | 0; diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index a8e970d2d42103..c071d761b845fc 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -23,7 +23,6 @@ const assert = require('internal/assert'); const Stream = require('stream'); -const util = require('util'); const internalUtil = require('internal/util'); const { outHeadersKey, utcDate } = require('internal/http'); const { Buffer } = require('buffer'); @@ -104,7 +103,8 @@ function OutgoingMessage() { this._onPendingData = noopPendingOutput; } -util.inherits(OutgoingMessage, Stream); +Object.setPrototypeOf(OutgoingMessage.prototype, Stream.prototype); +Object.setPrototypeOf(OutgoingMessage, Stream); Object.defineProperty(OutgoingMessage.prototype, '_headers', { diff --git a/lib/_http_server.js b/lib/_http_server.js index 752148e0de44c9..069c2670b80e43 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -21,7 +21,6 @@ 'use strict'; -const util = require('util'); const net = require('net'); const assert = require('internal/assert'); const { @@ -136,7 +135,8 @@ function ServerResponse(req) { this.shouldKeepAlive = false; } } -util.inherits(ServerResponse, OutgoingMessage); +Object.setPrototypeOf(ServerResponse.prototype, OutgoingMessage.prototype); +Object.setPrototypeOf(ServerResponse, OutgoingMessage); ServerResponse.prototype._finish = function _finish() { DTRACE_HTTP_SERVER_RESPONSE(this.connection); @@ -306,7 +306,8 @@ function Server(options, requestListener) { this.maxHeadersCount = null; this.headersTimeout = 40 * 1000; // 40 seconds } -util.inherits(Server, net.Server); +Object.setPrototypeOf(Server.prototype, net.Server.prototype); +Object.setPrototypeOf(Server, net.Server); Server.prototype.setTimeout = function setTimeout(msecs, callback) {