@@ -206,6 +206,18 @@ function getConnectionOptions(secureContext: SecureContext, verifyOptions: Verif
206206 const connectionOptions : ConnectionOptions = {
207207 secureContext : secureContext
208208 } ;
209+ let realTarget : GrpcUri = channelTarget ;
210+ if ( 'grpc.http_connect_target' in options ) {
211+ const parsedTarget = parseUri ( options [ 'grpc.http_connect_target' ] ! ) ;
212+ if ( parsedTarget ) {
213+ realTarget = parsedTarget ;
214+ }
215+ }
216+ const targetPath = getDefaultAuthority ( realTarget ) ;
217+ const hostPort = splitHostPort ( targetPath ) ;
218+ const remoteHost = hostPort ?. host ?? targetPath ;
219+ connectionOptions . host = remoteHost ;
220+
209221 if ( verifyOptions . checkServerIdentity ) {
210222 connectionOptions . checkServerIdentity = verifyOptions . checkServerIdentity ;
211223 }
@@ -225,36 +237,11 @@ function getConnectionOptions(secureContext: SecureContext, verifyOptions: Verif
225237 } ;
226238 connectionOptions . servername = sslTargetNameOverride ;
227239 } else {
228- if ( 'grpc.http_connect_target' in options ) {
229- /* This is more or less how servername will be set in createSession
230- * if a connection is successfully established through the proxy.
231- * If the proxy is not used, these connectionOptions are discarded
232- * anyway */
233- const targetPath = getDefaultAuthority (
234- parseUri ( options [ 'grpc.http_connect_target' ] as string ) ?? {
235- path : 'localhost' ,
236- }
237- ) ;
238- const hostPort = splitHostPort ( targetPath ) ;
239- connectionOptions . servername = hostPort ?. host ?? targetPath ;
240- }
240+ connectionOptions . servername = remoteHost ;
241241 }
242242 if ( options [ 'grpc-node.tls_enable_trace' ] ) {
243243 connectionOptions . enableTrace = true ;
244244 }
245-
246- let realTarget : GrpcUri = channelTarget ;
247- if ( 'grpc.http_connect_target' in options ) {
248- const parsedTarget = parseUri ( options [ 'grpc.http_connect_target' ] ! ) ;
249- if ( parsedTarget ) {
250- realTarget = parsedTarget ;
251- }
252- }
253- const targetPath = getDefaultAuthority ( realTarget ) ;
254- const hostPort = splitHostPort ( targetPath ) ;
255- const remoteHost = hostPort ?. host ?? targetPath ;
256- connectionOptions . host = remoteHost ;
257- connectionOptions . servername = remoteHost ;
258245 return connectionOptions ;
259246}
260247
@@ -268,7 +255,7 @@ class SecureConnectorImpl implements SecureConnector {
268255 } ;
269256 return new Promise < SecureConnectResult > ( ( resolve , reject ) => {
270257 const tlsSocket = tlsConnect ( tlsConnectOptions , ( ) => {
271- if ( ! tlsSocket . authorized ) {
258+ if ( ( this . connectionOptions . rejectUnauthorized ?? true ) && ! tlsSocket . authorized ) {
272259 reject ( tlsSocket . authorizationError ) ;
273260 return ;
274261 }
@@ -364,7 +351,7 @@ class CertificateProviderChannelCredentialsImpl extends ChannelCredentials {
364351 const tlsSocket = tlsConnect ( tlsConnectOptions , ( ) => {
365352 tlsSocket . removeListener ( 'close' , closeCallback ) ;
366353 tlsSocket . removeListener ( 'error' , errorCallback ) ;
367- if ( ! tlsSocket . authorized ) {
354+ if ( ( this . parent . verifyOptions . rejectUnauthorized ?? true ) && ! tlsSocket . authorized ) {
368355 reject ( tlsSocket . authorizationError ) ;
369356 return ;
370357 }
0 commit comments