mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
http: refactor to make servername option normalization testable
Refs: https://coverage.nodejs.org/coverage-36bb31be5f0b85a0/lib/_http_agent.js.html#L316 PR-URL: https://github.com/nodejs/node/pull/38733 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
@@ -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]) {
|
||||
@@ -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;
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user