Comparing version 1.2.1 to 1.2.2
21
index.js
@@ -15,2 +15,3 @@ const dns = require('node:dns'); | ||
const pMap = require('p-map'); | ||
const pTimeout = require('p-timeout'); | ||
const pWaitFor = require('p-wait-for'); | ||
@@ -73,2 +74,4 @@ const packet = require('dns-packet'); | ||
err = errors[0]; | ||
} else if (errors.every((e) => e instanceof pTimeout.TimeoutError)) { | ||
err = errors[0]; | ||
} else { | ||
@@ -81,2 +84,10 @@ err = new Error( | ||
); | ||
// if all errors had `name` and they were all the same then preserve it | ||
if ( | ||
typeof errors[0].name !== 'undefined' && | ||
errors.every((e) => e.name === errors[0].name) | ||
) | ||
err.name = errors[0].name; | ||
// if all errors had `code` and they were all the same then preserve it | ||
@@ -257,3 +268,2 @@ if ( | ||
}, | ||
requestTimeout: (ms) => ({ bodyTimeout: ms }), | ||
// | ||
@@ -763,3 +773,2 @@ // NOTE: we set the default to "get" since it is faster from `benchmark` results | ||
...this.options.requestOptions, | ||
...this.options.requestTimeout(timeout), // returns `{ bodyTimeout: requestTimeout }` | ||
signal: abortController.signal | ||
@@ -780,3 +789,5 @@ }; | ||
debug('request', { url, options }); | ||
const response = await this.request(url, options); | ||
const response = await pTimeout(this.request(url, options), timeout, { | ||
signal: abortController.signal | ||
}); | ||
return response; | ||
@@ -910,3 +921,5 @@ } | ||
rrtype, | ||
_err.code, | ||
_err instanceof pTimeout.TimeoutError || _err.name === 'TimeoutError' | ||
? dns.TIMEOUT | ||
: _err.code, | ||
_err.errno | ||
@@ -913,0 +926,0 @@ ); |
{ | ||
"name": "tangerine", | ||
"description": "Tangerine is the best Node.js drop-in replacement for dns.promises.Resolver using DNS over HTTPS (\"DoH\") via undici with built-in retries, timeouts, smart server rotation, AbortControllers, and caching support for multiple backends via Keyv.", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"author": "Forward Email (https://forwardemail.net)", | ||
@@ -20,2 +20,3 @@ "bugs": { | ||
"p-map": "4", | ||
"p-timeout": "4", | ||
"p-wait-for": "3", | ||
@@ -22,0 +23,0 @@ "port-numbers": "^6.0.1", |
@@ -214,4 +214,3 @@ <h1 align="center"> | ||
} | ||
}, | ||
requestTimeout: (ms) => ({ timeout: { request: ms } }) | ||
} | ||
}, | ||
@@ -227,4 +226,2 @@ got | ||
* Specify default request options based off the library under `requestOptions` below | ||
* See `requestTimeout` function below, as it is required to be set properly if you are using a custom HTTP library function. | ||
* Instance methods of [dns.promises.Resolver](https://nodejs.org/api/dns.html) are mirrored to :tangerine: Tangerine. | ||
@@ -292,3 +289,2 @@ * Resolver methods accept an optional `abortController` argument, which is an instance of [AbortController](https://developer.mozilla.org/en-US/docs/Web/API/AbortController). Note that :tangerine: Tangerine manages `AbortController` usage internally – so you most likely won't need to pass your own (see [index.js](https://github.com/forwardemail/tangerine/blob/main/index.js) for more insight). | ||
| `requestOptions.headers` | `Object` | Defaults to `{ 'content-type': 'application/dns-message', 'user-agent': pkg.name + "/" + pkg.version, accept: 'application/dns-message', bodyTimeout: timeout }`. | Default HTTP headers to use for DNS over HTTP ("DoH") requests. | | ||
| `requestTimeout` | `Function` | Defaults to `(ms) => ({ bodyTimeout })` for setting undici timeout properly. | This function accepts an argument `ms` which is the number of milliseconds to wait for the request to timeout (since we use a back-off strategy that mirrors the Node.js DNS module). This function is required to be passed and customized if you are using a custom HTTP library. If you're using a custom HTTP library such as `got`, you'd set this to `requestTimeout: (ms) => ({ timeout: { request: ms } })` | | ||
| `protocol` | `String` | Defaults to `"https"`. | Default HTTP protocol to use for DNS over HTTPS ("DoH") requests. | | ||
@@ -295,0 +291,0 @@ | `dnsOrder` | `String` | Defaults to `"verbatim"` for Node.js v17.0.0+ and `"ipv4first"` for older versions. | Sets the default result order of `lookup` invocations (see [dns.setDefaultResultOrder](https://nodejs.org/api/dns.html#dnssetdefaultresultorderorder) for more insight). | |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1244
100329
12
602
+ Addedp-timeout@4
+ Added@types/node@22.10.1(transitive)
+ Addedp-timeout@4.1.0(transitive)
+ Addedundici@7.0.0(transitive)
- Removed@types/node@22.10.0(transitive)
- Removedundici@6.21.0(transitive)