From 719dfd67afe4a6f09a470f6824562a26ea6fb612 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Filip=20=C5=A0?= Date: Tue, 29 Oct 2019 21:30:03 +0100 Subject: [PATCH] Handle other parameters --- dns/query.py | 31 ++++++++++++++++++++++--------- dns/query.pyi | 2 +- dns/resolver.py | 2 +- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/dns/query.py b/dns/query.py index 42bdd471..a741a866 100644 --- a/dns/query.py +++ b/dns/query.py @@ -207,14 +207,23 @@ def _destination_and_source(af, where, port, source, source_port): return (af, destination, source) -def https(query, nameserver, post=True): +def https(query, url, timeout=None, post=True, one_rr_per_rrset=False, ignore_trailing=False): """Return the response obtained after sending a query via DNS-over-HTTPS. - *query*, a ``dns.message.Message`` containing the query to send + *query*, a ``dns.message.Message``, the query to send. - *nameserver*, a ``str`` containing the nameserver URL. + *url*, a ``str``, the nameserver URL. - *post*, a ``bool`` indicating whether POST method should be used. + *timeout*, a ``float`` or ``None``, the number of seconds to + wait before the query times out. If ``None``, the default, wait forever. + + *post*, a ``bool``. If ``True``, the default, POST method should be used. + + *one_rr_per_rrset*, a ``bool``. If ``True``, put each RR into its own + RRset. + + *ignore_trailing*, a ``bool``. If ``True``, ignore trailing + junk at end of the received message. Returns a ``dns.message.Message``. """ @@ -226,13 +235,17 @@ def https(query, nameserver, post=True): } if post: - request = urllib.request.Request(nameserver, data=wirequery, headers=headers) + request = urllib.request.Request(url, data=wirequery, headers=headers) else: wirequery = base64.urlsafe_b64encode(wirequery).decode('utf-8').strip('=') - request = urllib.request.Request(nameserver + '?dns=' + wirequery, headers=headers) - - response = urllib.request.urlopen(request).read() - return dns.message.from_wire(response) + request = urllib.request.Request(url + '?dns=' + wirequery, headers=headers) + + response = urllib.request.urlopen(request, timeout=timeout).read() + return dns.message.from_wire(response, + keyring=query.keyring, + request_mac=query.request_mac + one_rr_per_rrset=one_rr_per_rrset, + ignore_trailing=ignore_trailing) def send_udp(sock, what, destination, expiration=None): """Send a DNS message to the specified UDP socket. diff --git a/dns/query.pyi b/dns/query.pyi index c115de99..98fdc366 100644 --- a/dns/query.pyi +++ b/dns/query.pyi @@ -7,7 +7,7 @@ except ImportError: class ssl(object): SSLContext = {} -def https(query : message.Message, nameserver : str, post=True) -> message.Message: +def https(query : message.Message, url : str, timeout : float = None, post : Optional[bool] = True, one_rr_per_rrset : Optional[bool] = False, ignore_trailing : Optional[bool] = False) -> message.Message: pass def tcp(q : message.Message, where : str, timeout : float = None, port=53, af : Optional[int] = None, source : Optional[str] = None, source_port : Optional[int] = 0, diff --git a/dns/resolver.py b/dns/resolver.py index 3e2cc0d2..c49598fe 100644 --- a/dns/resolver.py +++ b/dns/resolver.py @@ -909,7 +909,7 @@ class Resolver(object): try: if protocol == 'https': tcp_attempt = True - response = dns.query.https(request, nameserver) + response = dns.query.https(request, nameserver, timeout) elif protocol: continue else: -- 2.47.3