UNPKG

dohdec

Version:

DNS over HTTPS and DNS over TLS

141 lines (140 loc) 4.77 kB
/** * Options for doing DOH lookups. * * @typedef {object} DOH_SpecificLookupOptions * @property {boolean} [preferPost=true] For DNS format requests, should * the HTTP POST verb be used? If false, uses GET. * @property {string} [url=CLOUDFLARE_API] What DoH endpoint should be * used? * @property {boolean} [json=true] Force JSON lookups for DOH. */ /** * @typedef {DOH_SpecificLookupOptions & * import('./dnsUtils.js').LookupOptions} DOH_LookupOptions */ /** * @typedef {import('./dnsUtils.js').Writable} Writable */ /** * Request DNS information over HTTPS. The [lookup]{@link DNSoverHTTPS#lookup} * function provides the easiest-to-use defaults. */ export class DNSoverHTTPS extends DNSutils { /** * The user-agent used in HTTPS requests. * @type {string} */ static userAgent: string; /** * The running version of dohdec. * @type {string} */ static version: string; /** * Default URL for DNSoverHTTPS requests * @type {string} */ static defaultURL: string; /** * Create a DNSoverHTTPS instance. * * @param {object} opts Options for all requests. * @param {string} [opts.userAgent="packageName version"] User Agent for * HTTP request. * @param {string} [opts.url="https://cloudflare-dns.com/dns-query"] Base URL * for all HTTP requests. * @param {boolean} [opts.preferPost=true] Should POST be preferred to Get * for DNS-format queries? * @param {string} [opts.contentType="application/dns-udpwireformat"] * MIME type for POST. * @param {number} [opts.verbose=0] How verbose do you want your logging? * @param {Writable} [opts.verboseStream=process.stderr] Where to write * verbose output. * @param {boolean} [opts.http2=false] Use http/2 if it is available. */ constructor(opts?: { userAgent?: string | undefined; url?: string | undefined; preferPost?: boolean | undefined; contentType?: string | undefined; verbose?: number | undefined; verboseStream?: import("./dnsUtils.js").Writable | undefined; http2?: boolean | undefined; }); opts: { userAgent: string; url: string; preferPost: boolean; contentType: string; http2: boolean; }; hooks: { beforeRequest: ((options: import("got").Options) => void)[]; } | undefined; /** * @private * @ignore */ private _checkServerIdentity; /** * Get a DNS-format response. * * @param {DOH_LookupOptions} opts Options for the request. * @returns {Promise<Buffer|object>} DNS result. */ getDNS(opts: DOH_LookupOptions): Promise<Buffer | object>; /** * Make a HTTPS GET request for JSON DNS. * * @param {object} opts Options for the request. * @param {string} [opts.name] The name to look up. * @param {string} [opts.rrtype="A"] The record type to look up. * @param {boolean} [opts.decode=true] Parse the returned JSON? * @param {boolean} [opts.dnssec=false] Request DNSSEC records. * @param {boolean} [opts.dnssecCheckingDisabled=false] Disable DNSSEC * validation. * @returns {Promise<string|object>} DNS result. */ getJSON(opts: { name?: string | undefined; rrtype?: string | undefined; decode?: boolean | undefined; dnssec?: boolean | undefined; dnssecCheckingDisabled?: boolean | undefined; }): Promise<string | object>; /** * Look up a DNS entry using DNS-over-HTTPS (DoH). * * @param {string|DOH_LookupOptions} name The DNS name to look up, or opts * if this is an object. * @param {DOH_LookupOptions|string} [opts={}] Options for the * request. If a string is given, it will be used as the rrtype. * @returns {Promise<Buffer|string|packet.Packet|object>} DNS result. */ lookup(name: string | DOH_LookupOptions, opts?: DOH_LookupOptions | string): Promise<Buffer | string | packet.Packet | object>; close(): void; } export default DNSoverHTTPS; /** * Options for doing DOH lookups. */ export type DOH_SpecificLookupOptions = { /** * For DNS format requests, should * the HTTP POST verb be used? If false, uses GET. */ preferPost?: boolean | undefined; /** * What DoH endpoint should be * used? */ url?: string | undefined; /** * Force JSON lookups for DOH. */ json?: boolean | undefined; }; export type DOH_LookupOptions = DOH_SpecificLookupOptions & import("./dnsUtils.js").LookupOptions; export type Writable = import("./dnsUtils.js").Writable; import DNSutils from './dnsUtils.js'; import * as packet from 'dns-packet';