Skip to content

Commit

Permalink
http: add default argument for Agent.prototype.getName
Browse files Browse the repository at this point in the history
PR-URL: #41906
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Ricky Zhou <[email protected]>
Reviewed-By: Mestery <[email protected]>
  • Loading branch information
xtx1130 authored and danielleadams committed Apr 24, 2022
1 parent 29fd5ff commit 16c00c6
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
6 changes: 5 additions & 1 deletion doc/api/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,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
Expand Down
2 changes: 1 addition & 1 deletion lib/_http_agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 += ':';
Expand Down
2 changes: 1 addition & 1 deletion lib/https.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 += ':';
Expand Down
8 changes: 7 additions & 1 deletion test/parallel/test-http-agent-getname.js
Original file line number Diff line number Diff line change
Expand Up @@ -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::'
Expand Down
6 changes: 6 additions & 0 deletions test/parallel/test-https-agent-getname.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({}),
Expand Down

0 comments on commit 16c00c6

Please sign in to comment.