@@ -35,6 +35,17 @@ const agent_base_1 = require("agent-base");
3535const url_1 = require ( "url" ) ;
3636const parse_proxy_response_1 = require ( "./parse-proxy-response" ) ;
3737const debug = ( 0 , debug_1 . default ) ( 'https-proxy-agent' ) ;
38+ const setServernameFromNonIpHost = ( options ) => {
39+ if ( options . servername === undefined &&
40+ options . host &&
41+ ! net . isIP ( options . host ) ) {
42+ return {
43+ ...options ,
44+ servername : options . host ,
45+ } ;
46+ }
47+ return options ;
48+ } ;
3849/**
3950 * The `HttpsProxyAgent` implements an HTTP Agent subclass that connects to
4051 * the specified "HTTP(s) proxy server" in order to proxy HTTPS requests.
@@ -82,11 +93,7 @@ class HttpsProxyAgent extends agent_base_1.Agent {
8293 let socket ;
8394 if ( proxy . protocol === 'https:' ) {
8495 debug ( 'Creating `tls.Socket`: %o' , this . connectOpts ) ;
85- const servername = this . connectOpts . servername || this . connectOpts . host ;
86- socket = tls . connect ( {
87- ...this . connectOpts ,
88- servername,
89- } ) ;
96+ socket = tls . connect ( setServernameFromNonIpHost ( this . connectOpts ) ) ;
9097 }
9198 else {
9299 debug ( 'Creating `net.Socket`: %o' , this . connectOpts ) ;
@@ -122,11 +129,9 @@ class HttpsProxyAgent extends agent_base_1.Agent {
122129 // The proxy is connecting to a TLS server, so upgrade
123130 // this socket connection to a TLS connection.
124131 debug ( 'Upgrading socket connection to TLS' ) ;
125- const servername = opts . servername || opts . host ;
126132 return tls . connect ( {
127- ...omit ( opts , 'host' , 'path' , 'port' ) ,
133+ ...omit ( setServernameFromNonIpHost ( opts ) , 'host' , 'path' , 'port' ) ,
128134 socket,
129- servername,
130135 } ) ;
131136 }
132137 return socket ;
0 commit comments