Skip to content

Commit b866e38

Browse files
authored
http: refactor to make servername option normalization testable
Refs: https://coverage.nodejs.org/coverage-36bb31be5f0b85a0/lib/_http_agent.js.html#L316 PR-URL: #38733 Reviewed-By: Antoine du Hamel <[email protected]>
1 parent 2ef1702 commit b866e38

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lib/_http_agent.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,7 @@ Agent.prototype.addRequest = function addRequest(req, options, port/* legacy */,
253253
if (options.socketPath)
254254
options.path = options.socketPath;
255255

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

259258
const name = this.getName(options);
260259
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;
@@ -344,6 +342,11 @@ Agent.prototype.createSocket = function createSocket(req, options, cb) {
344342
oncreate(null, newSocket);
345343
};
346344

345+
function normalizeServerName(options, req) {
346+
if (!options.servername && options.servername !== '')
347+
options.servername = calculateServerName(options, req);
348+
}
349+
347350
function calculateServerName(options, req) {
348351
let servername = options.host;
349352
const hostHeader = req.getHeader('host');

0 commit comments

Comments
 (0)