Changes user-agent

This commit is contained in:
Pierre Lannoy 2023-12-13 20:07:14 +01:00
commit 108335b50c
Signed by: Pierre Lannoy
GPG key ID: D27231EF87D53F31

View file

@ -68,7 +68,7 @@ function sendDohMsg(packet, url, timeout) {
let requestOptions; let requestOptions;
const headers = { const headers = {
'Accept': 'application/dns-message', 'Accept': 'application/dns-message',
'User-Agent': 'domain-forward/1.0.0' 'User-Agent': 'domain-forward/1.x'
}; };
const dnsQueryParam = buf.toString('base64').toString('utf-8').replace(/=/g, ''); const dnsQueryParam = buf.toString('base64').toString('utf-8').replace(/=/g, '');
url = `${url}?dns=${dnsQueryParam}`; url = `${url}?dns=${dnsQueryParam}`;
@ -116,58 +116,4 @@ function sendDohMsg(packet, url, timeout) {
}); });
} }
/**
* 'Prettifies' a dnsPacket message.
*
* Namely, this convert Buffers the the appropriate presentation format.
* This is useful to make json human readable.
*
* *NOTE* This function may modify the message such that it no longer works with dnsPacket.
* Caution should be used when calling this object on query packets before sending them
*
* @param msg {object} a dnsPacket
* @returns {object} the msg which has been modified in-place. *May not be a valid <dnsPacket> afterwards*
*/
function prettify(msg) {
for (const rr of (msg['answers'] || []).concat((msg['authorities'] || []))) {
if (rr.hasOwnProperty('data')) {
switch (rr.type) {
case 'TXT':
rr.data = rr.data.toString('utf8');
break;
case 'DNSKEY':
rr.data.key = rr.data.key.toString('base64').replace('=', '');
break;
case 'DS':
rr.data.digest = rr.data.digest.toString('hex');
break;
case 'NSEC3':
rr.data.salt = rr.data.salt.toString('hex');
rr.data.nextDomain = base32Encode(rr.data.nextDomain, 'RFC4648-HEX').replace('=', '')
break;
case 'RRSIG':
rr.data.signature = rr.data.signature.toString('base64').replace('=', '');
break;
}
}
}
for (const rr of (msg['additionals'] || [])) {
if (rr.type === 'OPT') {
for (const opt of rr['options']) {
switch(opt.code) {
case 12:
opt.length = opt.data.length;
opt.data = opt.data.toString('hex').substring(0, 80);
if (opt.data.length === 80 ) {
opt.data += '...'
}
break;
}
}
}
}
return msg
}
export default DohResolver; export default DohResolver;