mirror of https://github.com/nodejs/node.git
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
parent
0f2ab70542
commit
04c68ba54a
|
@ -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
|
||||
|
|
|
@ -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 += ':';
|
||||
|
|
|
@ -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 += ':';
|
||||
|
|
|
@ -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::'
|
||||
|
|
|
@ -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({}),
|
||||
|
|
Loading…
Reference in New Issue