]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
Fix the DoH v6 literal fix.
authorBob Halley <halley@dnspython.org>
Tue, 16 Jun 2020 15:21:01 +0000 (08:21 -0700)
committerBob Halley <halley@dnspython.org>
Tue, 16 Jun 2020 15:21:01 +0000 (08:21 -0700)
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.

dns/query.py

index 0d76195ac58f8623889911644f9680c360dbaaeb..7402189b83e54bb8e79e096b5e2dbb3a0b0d3f84 100644 (file)
@@ -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)