From: Bob Halley Date: Tue, 16 Jun 2020 15:21:01 +0000 (-0700) Subject: Fix the DoH v6 literal fix. X-Git-Tag: v2.0.0rc1~93 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9f9d319be4f7c7f0612f72773afea012695f0ec0;p=thirdparty%2Fdnspython.git Fix the DoH v6 literal fix. My first try at this did not play well with the refactoring of _destination_and_source, as there will now be an af if source has one and destination doesn't. We only want to make special literal URLs when the destination is a literal. --- diff --git a/dns/query.py b/dns/query.py index 0d76195a..7402189b 100644 --- a/dns/query.py +++ b/dns/query.py @@ -314,17 +314,20 @@ def https(q, where, timeout=None, port=443, source=None, source_port=0, headers = { "accept": "application/dns-message" } - if af == dns.inet.AF_INET: - url = 'https://{}:{}{}'.format(where, port, path) - elif af == dns.inet.AF_INET6: - url = 'https://[{}]:{}{}'.format(where, port, path) - elif bootstrap_address is not None: - split_url = urllib.parse.urlsplit(where) - headers['Host'] = split_url.hostname - url = where.replace(split_url.hostname, bootstrap_address) - transport_adapter = HostHeaderSSLAdapter() - else: - url = where + try: + where_af = dns.inet.af_for_address(where) + if where_af == dns.inet.AF_INET: + url = 'https://{}:{}{}'.format(where, port, path) + elif where_af == dns.inet.AF_INET6: + url = 'https://[{}]:{}{}'.format(where, port, path) + except ValueError: + if bootstrap_address is not None: + split_url = urllib.parse.urlsplit(where) + headers['Host'] = split_url.hostname + url = where.replace(split_url.hostname, bootstrap_address) + transport_adapter = HostHeaderSSLAdapter() + else: + url = where if source is not None: # set source port and source address transport_adapter = SourceAddressAdapter(source)