Skip to content

Commit d30f7a8

Browse files
xtx1130danielleadams
authored andcommitted
http: add default argument for Agent.prototype.getName
PR-URL: #41906 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ricky Zhou <0x19951125@gmail.com> Reviewed-By: Mestery <mestery@protonmail.com>
1 parent cb42cf0 commit d30f7a8

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

doc/api/http.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,14 @@ the agent when `keepAlive` is enabled. Do not modify.
294294
Sockets in the `freeSockets` list will be automatically destroyed and
295295
removed from the array on `'timeout'`.
296296

297-
### `agent.getName(options)`
297+
### `agent.getName([options])`
298298

299299
<!-- YAML
300300
added: v0.11.4
301+
changes:
302+
- version: REPLACEME
303+
pr-url: https://github.com/nodejs/node/pull/41906
304+
description: The `options` parameter is now optional.
301305
-->
302306

303307
* `options` {Object} A set of options providing information for name generation

lib/_http_agent.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ Agent.defaultMaxSockets = Infinity;
217217
Agent.prototype.createConnection = net.createConnection;
218218

219219
// Get the key for a given set of request options
220-
Agent.prototype.getName = function getName(options) {
220+
Agent.prototype.getName = function getName(options = {}) {
221221
let name = options.host || 'localhost';
222222

223223
name += ':';

lib/https.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ Agent.prototype.createConnection = createConnection;
203203
* }} [options]
204204
* @returns {string}
205205
*/
206-
Agent.prototype.getName = function getName(options) {
206+
Agent.prototype.getName = function getName(options = {}) {
207207
let name = FunctionPrototypeCall(HttpAgent.prototype.getName, this, options);
208208

209209
name += ':';

test/parallel/test-http-agent-getname.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ assert.strictEqual(
1818
'localhost:80:192.168.1.1'
1919
);
2020

21-
// empty
21+
// empty argument
22+
assert.strictEqual(
23+
agent.getName(),
24+
'localhost::'
25+
);
26+
27+
// empty options
2228
assert.strictEqual(
2329
agent.getName({}),
2430
'localhost::'

test/parallel/test-https-agent-getname.js

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ const https = require('https');
99

1010
const agent = new https.Agent();
1111

12+
// empty argument
13+
assert.strictEqual(
14+
agent.getName(),
15+
'localhost::::::::::::::::::::::'
16+
);
17+
1218
// empty options
1319
assert.strictEqual(
1420
agent.getName({}),

0 commit comments

Comments
 (0)