@@ -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+
343346function calculateServerName ( options , req ) {
344347 let servername = options . host ;
345348 const hostHeader = req . getHeader ( 'host' ) ;
0 commit comments