Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
http: refactor to make servername option normalization testable
  • Loading branch information
pd4d10 authored and aduh95 committed Sep 20, 2023
commit b43137afb457346c802ceb92317f69b25d41026d
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);
}

Comment on lines +345 to +349
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we avoid mutating an argument in a function?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it would be good to refactor that away. But can happen in a follow up PR.

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