File tree 6 files changed +42
-11
lines changed
6 files changed +42
-11
lines changed Original file line number Diff line number Diff line change @@ -340,7 +340,14 @@ export interface Server {
340
340
tlsName : string ;
341
341
342
342
resolve (
343
- opts : Partial < { fn : DnsResolveFn ; randomize : boolean ; debug ?: boolean } > ,
343
+ opts : Partial <
344
+ {
345
+ fn : DnsResolveFn ;
346
+ randomize : boolean ;
347
+ debug ?: boolean ;
348
+ resolve ?: boolean ;
349
+ }
350
+ > ,
344
351
) : Promise < Server [ ] > ;
345
352
}
346
353
@@ -1404,10 +1411,12 @@ export interface ConnectionOptions {
1404
1411
noAsyncTraces ?: boolean ;
1405
1412
1406
1413
/**
1407
- * When true, the connect function will remove any name resolution provided by
1408
- * the transport. In some environments (browsers) this is a no-op option.
1414
+ * When false, the connect function will not perform any hostname resolution. Note that
1415
+ * by default this option will be true if the client supports hostname resolution.
1416
+ * Note that on clients that don't supported (mainly the websocket client, setting this
1417
+ * option to true, will throw an exception as this option is not available.
1409
1418
*/
1410
- noResolve ?: boolean ;
1419
+ resolve ?: boolean ;
1411
1420
}
1412
1421
1413
1422
/**
Original file line number Diff line number Diff line change @@ -135,6 +135,12 @@ export function parseOptions(opts?: ConnectionOptions): ConnectionOptions {
135
135
}
136
136
}
137
137
138
+ // if not set - we set it
139
+ if ( options . resolve === undefined ) {
140
+ // set a default based on whether the client can resolve or not
141
+ options . resolve = typeof getResolveFn ( ) === "function" ;
142
+ }
143
+
138
144
if ( options . resolve ) {
139
145
if ( typeof getResolveFn ( ) !== "function" ) {
140
146
throw new NatsError (
Original file line number Diff line number Diff line change @@ -594,10 +594,12 @@ export class ProtocolHandler implements Dispatcher<ParserEvent> {
594
594
}
595
595
596
596
async _doDial ( srv : Server ) : Promise < void > {
597
+ const { resolve } = this . options ;
597
598
const alts = await srv . resolve ( {
598
599
fn : getResolveFn ( ) ,
599
600
debug : this . options . debug ,
600
601
randomize : ! this . options . noRandomize ,
602
+ resolve,
601
603
} ) ;
602
604
603
605
let lastErr : Error | null = null ;
Original file line number Diff line number Diff line change @@ -138,12 +138,13 @@ export class ServerImpl implements Server {
138
138
fn : DnsResolveFn ;
139
139
randomize : boolean ;
140
140
resolve : boolean ;
141
- debug ? : boolean ;
141
+ debug : boolean ;
142
142
}
143
143
> ,
144
144
) : Promise < Server [ ] > {
145
- if ( ! opts . fn ) {
145
+ if ( ! opts . fn || opts . resolve === false ) {
146
146
// we cannot resolve - transport doesn't support it
147
+ // or user opted out
147
148
// don't add - to resolves or we get a circ reference
148
149
return [ this ] ;
149
150
}
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ export function connect(opts: ConnectionOptions = {}): Promise<NatsConnection> {
27
27
factory : ( ) : Transport => {
28
28
return new DenoTransport ( ) ;
29
29
} ,
30
- dnsResolveFn : opts . noResolve === true ? undefined : denoResolveHost ,
30
+ dnsResolveFn : denoResolveHost ,
31
31
} as TransportFactory ) ;
32
32
33
33
return NatsConnectionImpl . connect ( opts ) ;
Original file line number Diff line number Diff line change @@ -48,7 +48,6 @@ import {
48
48
collect ,
49
49
deferred ,
50
50
delay ,
51
- getResolveFn ,
52
51
headers ,
53
52
isIP ,
54
53
NatsConnectionImpl ,
@@ -1427,9 +1426,23 @@ Deno.test("basics - respond message", async () => {
1427
1426
} ) ;
1428
1427
1429
1428
Deno . test ( "basics - noResolve" , async ( ) => {
1430
- const { ns, nc } = await setup ( { } , { noResolve : true } ) ;
1431
- assertEquals ( getResolveFn ( ) , undefined ) ;
1432
- await cleanup ( ns , nc ) ;
1429
+ const token = Deno . env . get ( "NGS_CI_USER" ) ;
1430
+ if ( token === undefined ) {
1431
+ disabled (
1432
+ `skipping: NGS_CI_USER is not available in the environment` ,
1433
+ ) ;
1434
+ return ;
1435
+ }
1436
+
1437
+ const nci = await connect ( {
1438
+ servers : "connect.ngs.global" ,
1439
+ authenticator : jwtAuthenticator ( token ) ,
1440
+ resolve : false ,
1441
+ } ) as NatsConnectionImpl ;
1442
+
1443
+ const srv = nci . protocol . servers . getCurrentServer ( ) ;
1444
+ assertEquals ( srv . resolves , undefined ) ;
1445
+ await nci . close ( ) ;
1433
1446
} ) ;
1434
1447
1435
1448
class MM implements Msg {
You can’t perform that action at this time.
0 commit comments