@@ -31,9 +31,21 @@ const socks_1 = require("socks");
3131const agent_base_1 = require ( "agent-base" ) ;
3232const debug_1 = __importDefault ( require ( "debug" ) ) ;
3333const dns = __importStar ( require ( "dns" ) ) ;
34+ const net = __importStar ( require ( "net" ) ) ;
3435const tls = __importStar ( require ( "tls" ) ) ;
3536const url_1 = require ( "url" ) ;
3637const debug = ( 0 , debug_1 . default ) ( 'socks-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+ } ;
3749function parseSocksURL ( url ) {
3850 let lookup = false ;
3951 let type = 5 ;
@@ -149,11 +161,9 @@ class SocksProxyAgent extends agent_base_1.Agent {
149161 // The proxy is connecting to a TLS server, so upgrade
150162 // this socket connection to a TLS connection.
151163 debug ( 'Upgrading socket connection to TLS' ) ;
152- const servername = opts . servername || opts . host ;
153164 const tlsSocket = tls . connect ( {
154- ...omit ( opts , 'host' , 'path' , 'port' ) ,
165+ ...omit ( setServernameFromNonIpHost ( opts ) , 'host' , 'path' , 'port' ) ,
155166 socket,
156- servername,
157167 } ) ;
158168 tlsSocket . once ( 'error' , ( error ) => {
159169 debug ( 'Socket TLS error' , error . message ) ;
0 commit comments