From 5747d9f650aaff866db3a7c6079a646ab8299599 Mon Sep 17 00:00:00 2001 From: SindreXie Date: Wed, 9 Feb 2022 16:15:03 +0800 Subject: [PATCH 1/4] http: add default argument for Agent.prototype.getName --- lib/_http_agent.js | 2 +- lib/https.js | 2 +- test/parallel/test-http-agent-getname.js | 8 +++++++- test/parallel/test-https-agent-getname.js | 6 ++++++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/_http_agent.js b/lib/_http_agent.js index 9c15875762dd47..28759a91c4f5a1 100644 --- a/lib/_http_agent.js +++ b/lib/_http_agent.js @@ -217,7 +217,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 = {}) { let name = options.host || 'localhost'; name += ':'; diff --git a/lib/https.js b/lib/https.js index 695a9020994852..7a9a4243aaae14 100644 --- a/lib/https.js +++ b/lib/https.js @@ -203,7 +203,7 @@ Agent.prototype.createConnection = createConnection; * }} [options] * @returns {string} */ -Agent.prototype.getName = function getName(options) { +Agent.prototype.getName = function getName(options = {}) { let name = FunctionPrototypeCall(HttpAgent.prototype.getName, this, options); name += ':'; diff --git a/test/parallel/test-http-agent-getname.js b/test/parallel/test-http-agent-getname.js index ab946a4bde3ddf..14cfcfaabdf6f4 100644 --- a/test/parallel/test-http-agent-getname.js +++ b/test/parallel/test-http-agent-getname.js @@ -18,7 +18,13 @@ assert.strictEqual( 'localhost:80:192.168.1.1' ); -// empty +// empty argument +assert.strictEqual( + agent.getName(), + 'localhost::' +); + +// empty options assert.strictEqual( agent.getName({}), 'localhost::' diff --git a/test/parallel/test-https-agent-getname.js b/test/parallel/test-https-agent-getname.js index 6f8c32b299a669..2a13ab1c6f47ee 100644 --- a/test/parallel/test-https-agent-getname.js +++ b/test/parallel/test-https-agent-getname.js @@ -9,6 +9,12 @@ const https = require('https'); const agent = new https.Agent(); +// empty argument +assert.strictEqual( + agent.getName(), + 'localhost::::::::::::::::::::::' +); + // empty options assert.strictEqual( agent.getName({}), From f513e4a087b0c117e4b5b144b1b551abb317ca36 Mon Sep 17 00:00:00 2001 From: SindreXie Date: Thu, 10 Feb 2022 10:49:50 +0800 Subject: [PATCH 2/4] doc: change `agent.getName`'s argumnet to be optional --- doc/api/http.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/http.md b/doc/api/http.md index a0c27ea23d12ae..6f8f31c7fd6f67 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -296,7 +296,7 @@ the agent when `keepAlive` is enabled. Do not modify. Sockets in the `freeSockets` list will be automatically destroyed and removed from the array on `'timeout'`. -### `agent.getName(options)` +### `agent.getName([options])` * `options` {Object} A set of options providing information for name generation From 69a6bfbc143675582e766bd681923a092ad7f3eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=8F=9C?= Date: Sat, 12 Feb 2022 01:29:11 +0800 Subject: [PATCH 4/4] doc: Update doc/api/http.md Co-authored-by: Mestery --- doc/api/http.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/http.md b/doc/api/http.md index fd1494d34e25d9..67e781cfe8cd4d 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -303,7 +303,7 @@ added: v0.11.4 changes: - version: REPLACEME pr-url: https://github.com/nodejs/node/pull/41906 - description: The `option` parameter is now optional. + description: The `options` parameter is now optional. --> * `options` {Object} A set of options providing information for name generation