Socket
Socket
Sign inDemoInstall

cacheable-lookup

Package Overview
Dependencies
0
Maintainers
2
Versions
34
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 6.0.1 to 6.0.2

4

package.json
{
"name": "cacheable-lookup",
"version": "6.0.1",
"description": "A cacheable dns.lookup(…) that respects the TTL",
"version": "6.0.2",
"description": "A cacheable dns.lookup(…) that respects TTL",
"engines": {

@@ -6,0 +6,0 @@ "node": ">=10.6.0"

@@ -6,3 +6,3 @@ # cacheable-lookup

[![Node CI](https://github.com/szmarczak/cacheable-lookup/workflows/Node%20CI/badge.svg)](https://github.com/szmarczak/cacheable-lookup/actions)
[![Coverage Status](https://coveralls.io/repos/github/szmarczak/cacheable-lookup/badge.svg?branch=master)](https://coveralls.io/github/szmarczak/cacheable-lookup?branch=master)
[![codecov](https://codecov.io/gh/szmarczak/cacheable-lookup/branch/master/graph/badge.svg)](https://codecov.io/gh/szmarczak/cacheable-lookup)
[![npm](https://img.shields.io/npm/dm/cacheable-lookup.svg)](https://www.npmjs.com/package/cacheable-lookup)

@@ -32,6 +32,9 @@ [![install size](https://packagephobia.now.sh/badge?p=cacheable-lookup)](https://packagephobia.now.sh/result?p=cacheable-lookup)

const http = require('http');
const https = require('https');
const CacheableLookup = require('cacheable-lookup');
const cacheable = new CacheableLookup();
cacheable.install(http.globalAgent);
cacheable.install(https.globalAgent);

@@ -38,0 +41,0 @@ http.get('http://example.com', response => {

@@ -66,4 +66,16 @@ 'use strict';

const ignoreNoResultErrors = dnsPromise => {
return dnsPromise.catch(error => {
if (error.code === 'ENODATA' || error.code === 'ENOTFOUND') {
return [];
}
throw error;
});
};
const ttl = {ttl: true};
const all = {all: true};
const all4 = {all: true, family: 4};
const all6 = {all: true, family: 6};

@@ -226,19 +238,7 @@ class CacheableLookup {

async _resolve(hostname) {
const wrap = async promise => {
try {
return await promise;
} catch (error) {
if (error.code === 'ENODATA' || error.code === 'ENOTFOUND') {
return [];
}
throw error;
}
};
// ANY is unsafe as it doesn't trigger new queries in the underlying server.
const [A, AAAA] = await Promise.all([
this._resolve4(hostname, ttl),
this._resolve6(hostname, ttl)
].map(promise => wrap(promise)));
ignoreNoResultErrors(this._resolve4(hostname, ttl)),
ignoreNoResultErrors(this._resolve6(hostname, ttl))
]);

@@ -285,17 +285,16 @@ let aTtl = 0;

async _lookup(hostname) {
try {
const entries = await this._dnsLookup(hostname, {
all: true
});
const [A, AAAA] = await Promise.all([
// Passing {all: true} doesn't return all IPv4 and IPv6 entries.
// See https://github.com/szmarczak/cacheable-lookup/issues/42
ignoreNoResultErrors(this._dnsLookup(hostname, all4)),
ignoreNoResultErrors(this._dnsLookup(hostname, all6))
]);
return {
entries,
cacheTtl: 0
};
} catch (_) {
return {
entries: [],
cacheTtl: 0
};
}
return {
entries: [
...A,
...AAAA
],
cacheTtl: 0
};
}

@@ -302,0 +301,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc