Fixes Google DoH lookups always falling back to Cloudflare (#49)

This commit is contained in:
Iain committed 2026-09-30 16:23:47 +01:00
1 parent 012e2db9aa
commit 53cc96ad81
2 files changed
+6 -3

No files matched your search

@@ -46,7 +46,7 @@ interface IndividualRecord {
// DNS over HTTPS endpoints
const DOH_ENDPOINTS = {
cloudflare: 'https://cloudflare-dns.com/dns-query',
google: 'https://dns.google/dns-query',
google: 'https://dns.google/resolve',
quad9: 'https://dns.quad9.net/dns-query',
opendns: 'https://doh.opendns.com/dns-query',
};
@@ -97,9 +97,12 @@
}) as DnsResult[];
if (successfulResults.length === 0) return false;
const firstAnswer = successfulResults[0].result!.Answer!.map((a) => a.data).sort();
// Cloudflare quotes TXT strings and splits long ones, Google returns them joined
const normalize = (data: string) =>
lastQuery?.type === 'TXT' ? data.replace(/^"(.*)"$/, '$1').replace(/" "/g, '') : data;
const firstAnswer = successfulResults[0].result!.Answer!.map((a) => normalize(a.data)).sort();
return successfulResults.every((r) => {
const answers = r.result!.Answer!.map((a) => a.data).sort();
const answers = r.result!.Answer!.map((a) => normalize(a.data)).sort();
return JSON.stringify(answers) === JSON.stringify(firstAnswer);
});
}