Skip to content

Commit 0413736

Browse files
xtx1130sxa
authored andcommitted
http: add default argument for Agent.prototype.getName
PR-URL: #41906 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Ricky Zhou <[email protected]> Reviewed-By: Mestery <[email protected]>
1 parent 4c9f2b5 commit 0413736

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
@@ -296,10 +296,14 @@ the agent when `keepAlive` is enabled. Do not modify.
296296
Sockets in the `freeSockets` list will be automatically destroyed and
297297
removed from the array on `'timeout'`.
298298

299-
### `agent.getName(options)`
299+
### `agent.getName([options])`
300300

301301
<!-- YAML
302302
added: v0.11.4
303+
changes:
304+
- version: REPLACEME
305+
pr-url: https://github.com/nodejs/node/pull/41906
306+
description: The `options` parameter is now optional.
303307
-->
304308

305309
* `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)