From 57c3c67acc7ac5b1b36e6d9db3d97e34452ff6fe Mon Sep 17 00:00:00 2001 From: Lsong Date: Fri, 22 Aug 2025 16:14:42 +0800 Subject: [PATCH] fix #95 --- client/doh.js | 11 ++++++++--- example/client/doh.js | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/client/doh.js b/client/doh.js index 88d99d1..c9abcb1 100644 --- a/client/doh.js +++ b/client/doh.js @@ -37,11 +37,16 @@ const makeRequest = (url, query) => new Promise((resolve, reject) => { const index = url.indexOf('://'); if (index === -1) url = `https://${url}`; const u = new URL(url); + // The DNS query is included in a single variable named “dns” in the + // query component of the request URI. The value of the “dns” variable + // is the content of the DNS request message, encoded with base64url + // [RFC4648](https://datatracker.ietf.org/doc/html/rfc8484#section-4.1). + const searchParams = u.searchParams; + searchParams.set('dns', query); + u.search = searchParams.toString(); const get = protocols[u.protocol]; if (!get) throw new Error(`Unsupported protocol: ${u.protocol}, must be specified (http://, https:// or h2://)`); - if (!u.pathname) url += '/dns-query?dns={query}'; - url = url.replace('{query}', query); - const req = get(url, { headers: { accept: 'application/dns-message' } }, resolve); + const req = get(u.toString(), { headers: { accept: 'application/dns-message' } }, resolve); if (req) req.on('error', reject); }); diff --git a/example/client/doh.js b/example/client/doh.js index 0c11aea..7c6a9db 100644 --- a/example/client/doh.js +++ b/example/client/doh.js @@ -18,5 +18,5 @@ const { DOHClient } = require('../..'); // })('cdnjs.com', 'NS').then(console.log); DOHClient({ - dns: 'h2://ada.openbld.net/dns-query?dns={query}', + dns: 'https://1.0.0.1/dns-query', })('cdnjs.com', 'NS').then(console.log);