Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions client/doh.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
2 changes: 1 addition & 1 deletion example/client/doh.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Loading