Skip to content

Commit ac673df

Browse files
committed
http: refactor to make servername option normalization testable
Refs: https://coverage.nodejs.org/coverage-36bb31be5f0b85a0/lib/_http_agent.js.html#L316
1 parent 910efc2 commit ac673df

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lib/_http_agent.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,7 @@ Agent.prototype.addRequest = function addRequest(req, options, port/* legacy */,
252252
if (options.socketPath)
253253
options.path = options.socketPath;
254254

255-
if (!options.servername && options.servername !== '')
256-
options.servername = calculateServerName(options, req);
255+
normalizeServerName(options, req);
257256

258257
const name = this.getName(options);
259258
if (!this.sockets[name]) {
@@ -313,8 +312,7 @@ Agent.prototype.createSocket = function createSocket(req, options, cb) {
313312
if (options.socketPath)
314313
options.path = options.socketPath;
315314

316-
if (!options.servername && options.servername !== '')
317-
options.servername = calculateServerName(options, req);
315+
normalizeServerName(options, req);
318316

319317
const name = this.getName(options);
320318
options._agentKey = name;
@@ -340,6 +338,11 @@ Agent.prototype.createSocket = function createSocket(req, options, cb) {
340338
oncreate(null, newSocket);
341339
};
342340

341+
function normalizeServerName(options, req) {
342+
if (!options.servername && options.servername !== '')
343+
options.servername = calculateServerName(options, req);
344+
}
345+
343346
function calculateServerName(options, req) {
344347
let servername = options.host;
345348
const hostHeader = req.getHeader('host');

0 commit comments

Comments
 (0)