From a709a7155d41228fc8a89e701db40dd66f4a9518 Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Sat, 21 May 2022 17:52:47 +0800 Subject: [PATCH] http: use `kEmptyObject` PR-URL: https://github.com/nodejs/node/pull/43159 Reviewed-By: Matteo Collina Reviewed-By: Antoine du Hamel --- lib/_http_agent.js | 7 +++++-- lib/_http_client.js | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/_http_agent.js b/lib/_http_agent.js index ff2047d4ea..6784e88485 100644 --- a/lib/_http_agent.js +++ b/lib/_http_agent.js @@ -54,7 +54,10 @@ const { ERR_OUT_OF_RANGE, }, } = require('internal/errors'); -const { once } = require('internal/util'); +const { + kEmptyObject, + once, +} = require('internal/util'); const { validateNumber, validateOneOf, @@ -220,7 +223,7 @@ Agent.defaultMaxSockets = Infinity; Agent.prototype.createConnection = net.createConnection; // Get the key for a given set of request options -Agent.prototype.getName = function getName(options = {}) { +Agent.prototype.getName = function getName(options = kEmptyObject) { let name = options.host || 'localhost'; name += ':'; diff --git a/lib/_http_client.js b/lib/_http_client.js index 59329ff243..91906b85a3 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -43,7 +43,10 @@ const { const net = require('net'); const assert = require('internal/assert'); -const { once } = require('internal/util'); +const { + kEmptyObject, + once, +} = require('internal/util'); const { _checkIsHttpToken: checkIsHttpToken, freeParser, @@ -133,7 +136,7 @@ function ClientRequest(input, options, cb) { if (typeof options === 'function') { cb = options; - options = input || {}; + options = input || kEmptyObject; } else { options = ObjectAssign(input || {}, options); }