From 32b612e4a7e9b37b883f229277544a213495798c 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 --- lib/_http_agent.js | 3 +-- lib/_http_common.js | 2 +- lib/_http_outgoing.js | 9 ++++----- lib/_http_server.js | 4 ++-- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/_http_agent.js b/lib/_http_agent.js index 6d8d598ddc4ac2..e23b7224f15619 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. diff --git a/lib/_http_common.js b/lib/_http_common.js index 7ecef8b83d412b..8894ae6fca27ba 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 60ed6779c47979..d6e830e3f35770 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'); @@ -109,10 +108,10 @@ Object.setPrototypeOf(OutgoingMessage, Stream); Object.defineProperty(OutgoingMessage.prototype, '_headers', { - get: util.deprecate(function() { + get: internalUtil.deprecate(function() { return this.getHeaders(); }, 'OutgoingMessage.prototype._headers is deprecated', 'DEP0066'), - set: util.deprecate(function(val) { + set: internalUtil.deprecate(function(val) { if (val == null) { this[outHeadersKey] = null; } else if (typeof val === 'object') { @@ -127,7 +126,7 @@ Object.defineProperty(OutgoingMessage.prototype, '_headers', { }); Object.defineProperty(OutgoingMessage.prototype, '_headerNames', { - get: util.deprecate(function() { + get: internalUtil.deprecate(function() { const headers = this[outHeadersKey]; if (headers !== null) { const out = Object.create(null); @@ -141,7 +140,7 @@ Object.defineProperty(OutgoingMessage.prototype, '_headerNames', { } return null; }, 'OutgoingMessage.prototype._headerNames is deprecated', 'DEP0066'), - set: util.deprecate(function(val) { + set: internalUtil.deprecate(function(val) { if (typeof val === 'object' && val !== null) { const headers = this[outHeadersKey]; if (!headers) diff --git a/lib/_http_server.js b/lib/_http_server.js index 7c2798cc9a06fa..5b8225d11679a0 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 { @@ -310,7 +309,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) {