@@ -206,6 +206,18 @@ function getConnectionOptions(secureContext: SecureContext, verifyOptions: Verif
206
206
const connectionOptions : ConnectionOptions = {
207
207
secureContext : secureContext
208
208
} ;
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
+
209
221
if ( verifyOptions . checkServerIdentity ) {
210
222
connectionOptions . checkServerIdentity = verifyOptions . checkServerIdentity ;
211
223
}
@@ -225,36 +237,11 @@ function getConnectionOptions(secureContext: SecureContext, verifyOptions: Verif
225
237
} ;
226
238
connectionOptions . servername = sslTargetNameOverride ;
227
239
} 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 ;
241
241
}
242
242
if ( options [ 'grpc-node.tls_enable_trace' ] ) {
243
243
connectionOptions . enableTrace = true ;
244
244
}
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 ;
258
245
return connectionOptions ;
259
246
}
260
247
0 commit comments