Skip to content

Commit

Permalink
http: refactor to make servername option normalization testable
Browse files Browse the repository at this point in the history
  • Loading branch information
pd4d10 authored and debadree25 committed Apr 15, 2024
1 parent 1656c5b commit fe7c701
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/_http_agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,7 @@ Agent.prototype.addRequest = function addRequest(req, options, port/* legacy */,
if (options.socketPath)
options.path = options.socketPath;

if (!options.servername && options.servername !== '')
options.servername = calculateServerName(options, req);
normalizeServerName(options, req);

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

if (!options.servername && options.servername !== '')
options.servername = calculateServerName(options, req);
normalizeServerName(options, req);

const name = this.getName(options);
options._agentKey = name;
Expand Down Expand Up @@ -344,6 +342,11 @@ Agent.prototype.createSocket = function createSocket(req, options, cb) {
oncreate(null, newSocket);
};

function normalizeServerName(options, req) {
if (!options.servername && options.servername !== '')
options.servername = calculateServerName(options, req);
}

function calculateServerName(options, req) {
let servername = options.host;
const hostHeader = req.getHeader('host');
Expand Down

0 comments on commit fe7c701

Please sign in to comment.