source_port: int = 0, # pylint: disable=W0613
one_rr_per_rrset: bool = False,
ignore_trailing: bool = False,
- client: Optional["httpx.AsyncClient"] = None,
+ client: Optional["httpx.AsyncClient|dns.quic.AsyncQuicConnection"] = None,
path: str = "/dns-query",
post: bool = True,
verify: Union[bool, str] = True,
parsed.hostname, family # pyright: ignore
)
bootstrap_address = random.choice(list(answers.addresses()))
+ if client and not isinstance(client, dns.quic.AsyncQuicConnection): # pyright: ignore
+ raise ValueError("client parameter must be a dns.quic.AsyncQuicConnection.")
+ assert client is None or isinstance(client, dns.quic.AsyncQuicConnection)
return await _http3(
q,
bootstrap_address,
ignore_trailing,
verify=verify,
post=post,
+ connection=client,
)
if not have_doh:
raise NoDOH # pragma: no cover
# pylint: disable=possibly-used-before-assignment
if client and not isinstance(client, httpx.AsyncClient): # pyright: ignore
- raise ValueError("session parameter must be an httpx.AsyncClient")
+ raise ValueError("client parameter must be an httpx.AsyncClient")
# pylint: enable=possibly-used-before-assignment
wire = q.to_wire()
backend: Optional[dns.asyncbackend.Backend] = None,
hostname: Optional[str] = None,
post: bool = True,
+ connection: Optional[dns.quic.AsyncQuicConnection] = None,
) -> dns.message.Message:
if not dns.quic.have_quic:
raise NoDOH("DNS-over-HTTP3 is not available.") # pragma: no cover
q.id = 0
wire = q.to_wire()
- (cfactory, mfactory) = dns.quic.factories_for_backend(backend)
+ the_connection: dns.quic.AsyncQuicConnection
+ if connection:
+ cfactory = dns.quic.null_factory
+ mfactory = dns.quic.null_factory
+ else:
+ (cfactory, mfactory) = dns.quic.factories_for_backend(backend)
async with cfactory() as context:
async with mfactory(
context, verify_mode=verify, server_name=hostname, h3=True
) as the_manager:
- the_connection = the_manager.connect(where, port, source, source_port)
+ if connection:
+ the_connection = connection
+ else:
+ the_connection = the_manager.connect( # pyright: ignore
+ where, port, source, source_port
+ )
(start, expiration) = _compute_times(timeout)
- stream = await the_connection.make_stream(timeout)
+ stream = await the_connection.make_stream(timeout) # pyright: ignore
async with stream:
# note that send_h3() does not need await
stream.send_h3(url, wire, post)
assert parsed.hostname is not None # pyright: ignore
answers = resolver.resolve_name(parsed.hostname, family) # pyright: ignore
bootstrap_address = random.choice(list(answers.addresses()))
+ if session and not isinstance(session, dns.quic.SyncQuicConnection): # pyright: ignore
+ raise ValueError("session parameter must be a dns.quic.SyncQuicConnection.")
return _http3(
q,
bootstrap_address,
ignore_trailing,
verify=verify,
post=post,
+ connection=session,
)
if not have_doh:
verify: Union[bool, str] = True,
hostname: Optional[str] = None,
post: bool = True,
+ connection: Optional[dns.quic.SyncQuicConnection] = None,
) -> dns.message.Message:
if not dns.quic.have_quic:
raise NoDOH("DNS-over-HTTP3 is not available.") # pragma: no cover
q.id = 0
wire = q.to_wire()
- manager = dns.quic.SyncQuicManager(
- verify_mode=verify, server_name=hostname, h3=True # pyright: ignore
- )
+ the_connection: dns.quic.SyncQuicConnection
+ the_manager: dns.quic.SyncQuicManager
+ if connection:
+ manager: contextlib.AbstractContextManager = contextlib.nullcontext(None)
+ else:
+ manager = dns.quic.SyncQuicManager(
+ verify_mode=verify, server_name=hostname, h3=True # pyright: ignore
+ )
+ the_manager = manager # for type checking happiness
with manager:
- connection = manager.connect(where, port, source, source_port)
+ if connection:
+ the_connection = connection
+ else:
+ the_connection = the_manager.connect( # pyright: ignore
+ where, port, source, source_port
+ )
(start, expiration) = _compute_times(timeout)
- with connection.make_stream(timeout) as stream:
+ with the_connection.make_stream(timeout) as stream: # pyright: ignore
stream.send_h3(url, wire, post)
wire = stream.receive(_remaining(expiration))
_check_status(stream.headers(), where, wire)