MCPcopy Create free account
hub / github.com/rthalley/dnspython / https

Function https

dns/asyncquery.py:530–703  ·  view source on GitHub ↗

Return the response obtained after sending a query via DNS-over-HTTPS. *client*, a ``httpx.AsyncClient``. If provided, the client to use for the query. Unlike the other dnspython async functions, a backend cannot be provided in this function because httpx always auto-detects the a

(
    q: dns.message.Message,
    where: str,
    timeout: float | None = None,
    port: int = 443,
    source: str | None = None,
    source_port: int = 0,  # pylint: disable=W0613
    one_rr_per_rrset: bool = False,
    ignore_trailing: bool = False,
    client: Optional["httpx.AsyncClient|dns.quic.AsyncQuicConnection"] = None,
    path: str = "/dns-query",
    post: bool = True,
    verify: bool | str | ssl.SSLContext = True,
    bootstrap_address: str | None = None,
    resolver: Optional["dns.asyncresolver.Resolver"] = None,  # pyright: ignore
    family: int = socket.AF_UNSPEC,
    http_version: HTTPVersion = HTTPVersion.DEFAULT,
)

Source from the content-addressed store, hash-verified

528
529
530async def https(
531 q: dns.message.Message,
532 where: str,
533 timeout: float | None = None,
534 port: int = 443,
535 source: str | None = None,
536 source_port: int = 0, # pylint: disable=W0613
537 one_rr_per_rrset: bool = False,
538 ignore_trailing: bool = False,
539 client: Optional["httpx.AsyncClient|dns.quic.AsyncQuicConnection"] = None,
540 path: str = "/dns-query",
541 post: bool = True,
542 verify: bool | str | ssl.SSLContext = True,
543 bootstrap_address: str | None = None,
544 resolver: Optional["dns.asyncresolver.Resolver"] = None, # pyright: ignore
545 family: int = socket.AF_UNSPEC,
546 http_version: HTTPVersion = HTTPVersion.DEFAULT,
547) -> dns.message.Message:
548 """Return the response obtained after sending a query via DNS-over-HTTPS.
549
550 *client*, a ``httpx.AsyncClient``. If provided, the client to use for
551 the query.
552
553 Unlike the other dnspython async functions, a backend cannot be provided
554 in this function because httpx always auto-detects the async backend.
555
556 See :py:func:`dns.query.https()` for the documentation of the other
557 parameters, exceptions, and return type of this method.
558 """
559
560 try:
561 af = dns.inet.af_for_address(where)
562 except ValueError:
563 af = None
564 # we bind url and then override as pyright can't figure out all paths bind.
565 url = where
566 if af is not None and dns.inet.is_address(where):
567 if af == socket.AF_INET:
568 url = f"https://{where}:{port}{path}"
569 elif af == socket.AF_INET6:
570 url = f"https://[{where}]:{port}{path}"
571
572 extensions = {}
573 if bootstrap_address is None:
574 # pylint: disable=possibly-used-before-assignment
575 parsed = urllib.parse.urlparse(url)
576 if parsed.hostname is None:
577 raise ValueError("no hostname in URL")
578 if dns.inet.is_address(parsed.hostname):
579 bootstrap_address = parsed.hostname
580 extensions["sni_hostname"] = parsed.hostname
581 if parsed.port is not None:
582 port = parsed.port
583
584 if http_version == HTTPVersion.H3 or (
585 http_version == HTTPVersion.DEFAULT and not have_doh
586 ):
587 if bootstrap_address is None:

Callers

nothing calls this directly

Calls 12

NullContextClass · 0.90
addressesMethod · 0.80
is_responseMethod · 0.80
_maybe_get_resolverFunction · 0.70
_http3Function · 0.70
resolve_nameMethod · 0.45
to_wireMethod · 0.45
get_transport_classMethod · 0.45
updateMethod · 0.45
wait_forMethod · 0.45
decodeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…