Skip to content

Commit 051fefd

Browse files
committed
fix #95
1 parent e4fa035 commit 051fefd

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

client/doh.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,16 @@ const makeRequest = (url, query) => new Promise((resolve, reject) => {
3737
const index = url.indexOf('://');
3838
if (index === -1) url = `https://${url}`;
3939
const u = new URL(url);
40+
// The DNS query is included in a single variable named “dns” in the
41+
// query component of the request URI. The value of the “dns” variable
42+
// is the content of the DNS request message, encoded with base64url
43+
// [RFC4648](https://datatracker.ietf.org/doc/html/rfc8484#section-4.1).
44+
const searchParams = u.searchParams;
45+
searchParams.set('dns', query);
46+
u.search = searchParams.toString();
4047
const get = protocols[u.protocol];
4148
if (!get) throw new Error(`Unsupported protocol: ${u.protocol}, must be specified (http://, https:// or h2://)`);
42-
if (!u.pathname) url += '/dns-query?dns={query}';
43-
url = url.replace('{query}', query);
44-
const req = get(url, { headers: { accept: 'application/dns-message' } }, resolve);
49+
const req = get(u.toString(), { headers: { accept: 'application/dns-message' } }, resolve);
4550
if (req) req.on('error', reject);
4651
});
4752

example/client/doh.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ const { DOHClient } = require('../..');
1818
// })('cdnjs.com', 'NS').then(console.log);
1919

2020
DOHClient({
21-
dns: 'h2://ada.openbld.net/dns-query?dns={query}',
21+
dns: 'https://1.0.0.1/dns-query',
2222
})('cdnjs.com', 'NS').then(console.log);

0 commit comments

Comments
 (0)