Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
badGateway: function badGateway (message) {
return new createError.BadGateway(message)
},
socket.on('message', (message, { port, address }) => {
if (
message.length < 2 ||
message.readUInt16BE(0) !== nonceDnsId ||
address !== resolverAddress ||
port !== resolverPort
) {
return
}
message.writeUInt16BE(requestDnsId, 0)
if (request.method === HTTP2_METHOD_GET) {
let answers
try {
({ answers } = decode(message))
} catch (error) {
return next(new BadGateway())
}
const ttl = answers.reduce(smallestTtl, Infinity)
if (Number.isFinite(ttl)) {
response.setHeader(HTTP2_HEADER_CACHE_CONTROL, `max-age=${ttl}`)
}
}
response.setHeader(HTTP2_HEADER_CONTENT_LENGTH, message.length)
response.setHeader(HTTP2_HEADER_CONTENT_TYPE, dohMediaType)
response.end(message)
socket.close()
})
}