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