MarkLogic server prefers ipv4 addresses to ipv6 addresses.
Because the client's address factors into validation of the nonce in DIGEST authentication, the client must continue to use the same address while using the nonce.
In Java, it became necessary under heavy concurrency with DIGEST authentication to prefer ipv4 addresses explicitly on the client.
If that becomes necessary in Node.js, the HTTP request() in version 12 supports a lookup function:
https://nodejs.org/docs/latest-v14.x/api/http.html#http_http_request_options_callback
Presumably, that function has the same signature as dns.lookup() and could wrap a call to dns.lookup(), passing all of true and iterating over the returned array to filter out the ipv6 addresses if any ipv4 addresses are available:
https://nodejs.org/docs/latest-v14.x/api/dns.html#dns_dns_lookup_hostname_options_callback
Expanding on the speculation...
The marklogic.js module would require the Node.js dns builtin library:
const dns = require('dns');
The marklogic.js module would define an prefLookup() function with the same signature as dns.lookup that configures the options and provides a callback for the response:
function prefLookup(hostname, options, callback) {
let isMultipleLookup = false;
if (options instanceof Function) {
callback = options;
} else if (options instanceof Object && options.all === true) {
isMultipleLookup = true;
}
// pass the preferred addresses or address to the callback
const prefCallback = isMultipleLookup ? callback : (err, addresses) => {
if (err) {
callback.call(null, err);
} else {
let addressdef = null;
// look for an ipv4 address
for (int i=0; i < addresses.length; i++) {
const candidate = addresses[i];
if (candidate.family === 4) {
addressdef = candidate;
break;
}
}
// fallback to first ipv6 address
if (addressdef === null) {
addressdef = addresses[0];
}
callback.call(null, null, addressdef.address, addressdef.family);
}
};
dns.lookup(hostname, {all:true, verbatim:false}, prefCallback);
}
The initialization of the client would set the lookup property in the connection params to a reference to the prefLookup function.
In principle, that should work to prefer ipv4 addresses.
MarkLogic server prefers ipv4 addresses to ipv6 addresses.
Because the client's address factors into validation of the nonce in DIGEST authentication, the client must continue to use the same address while using the nonce.
In Java, it became necessary under heavy concurrency with DIGEST authentication to prefer ipv4 addresses explicitly on the client.
If that becomes necessary in Node.js, the HTTP request() in version 12 supports a lookup function:
https://nodejs.org/docs/latest-v14.x/api/http.html#http_http_request_options_callback
Presumably, that function has the same signature as dns.lookup() and could wrap a call to dns.lookup(), passing all of true and iterating over the returned array to filter out the ipv6 addresses if any ipv4 addresses are available:
https://nodejs.org/docs/latest-v14.x/api/dns.html#dns_dns_lookup_hostname_options_callback
Expanding on the speculation...
The marklogic.js module would require the Node.js dns builtin library:
The marklogic.js module would define an prefLookup() function with the same signature as dns.lookup that configures the options and provides a callback for the response:
The initialization of the client would set the lookup property in the connection params to a reference to the prefLookup function.
In principle, that should work to prefer ipv4 addresses.