Skip to content

Commit 4c74b88

Browse files
committed
http: simplify getName with destructuring and template literals
Use object destructuring to extract options properties and template literals to construct the name string, improving code readability and reducing intermediate string concatenations.
1 parent a5f3cd8 commit 4c74b88

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

lib/_http_agent.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -259,23 +259,16 @@ Agent.prototype.createConnection = function createConnection(...args) {
259259

260260
// Get the key for a given set of request options
261261
Agent.prototype.getName = function getName(options = kEmptyObject) {
262-
let name = options.host || 'localhost';
263-
264-
name += ':';
265-
if (options.port)
266-
name += options.port;
267-
268-
name += ':';
269-
if (options.localAddress)
270-
name += options.localAddress;
262+
const { host = 'localhost', port, localAddress, family, socketPath } = options;
263+
let name = `${host}:${port || ''}:${localAddress || ''}`;
271264

272265
// Pacify parallel/test-http-agent-getname by only appending
273266
// the ':' when options.family is set.
274-
if (options.family === 4 || options.family === 6)
275-
name += `:${options.family}`;
267+
if (family === 4 || family === 6)
268+
name += `:${family}`;
276269

277-
if (options.socketPath)
278-
name += `:${options.socketPath}`;
270+
if (socketPath)
271+
name += `:${socketPath}`;
279272

280273
return name;
281274
};

0 commit comments

Comments
 (0)