http: add default argument for Agent.prototype.getName

PR-URL: https://github.com/nodejs/node/pull/41906
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Ricky Zhou <0x19951125@gmail.com>
Reviewed-By: Mestery <mestery@protonmail.com>
pull/42150/head
小菜 2022-02-27 23:01:01 +08:00 committed by GitHub
parent 0f2ab70542
commit 04c68ba54a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 4 deletions

View File

@ -296,10 +296,14 @@ 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])`
<!-- YAML
added: v0.11.4
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/41906
description: The `options` parameter is now optional.
-->
* `options` {Object} A set of options providing information for name generation

View File

@ -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 += ':';

View File

@ -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 += ':';

View File

@ -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::'

View File

@ -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({}),