-
-
Notifications
You must be signed in to change notification settings - Fork 845
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Drop backend=...
argument.
#782
Comments
Note: I use a custom Backend to record the certificates of the HTTPS requests. Code:
[EDIT] As I understand, the code will be something like this (using the private API): from httpx._backend.auto import AutoBackend
from httpx._dispatch.connection_pool import ConnectionPool
class CustomBackend(AutoBackend):
async def open_tcp_stream(
self,
hostname: str,
port: int,
ssl_context: typing.Optional[ssl.SSLContext],
timeout: Timeout,
) -> BaseSocketStream:
value = await super().open_tcp_stream(hostname, port, ssl_context, timeout)
# use value.stream_reader._transport.get_extra_info('ssl_object')
return value
async def f(*args, **kwargs):
backend = CustomBackend()
dispatch = ConnectionPool(backend=backend, http2=True)
async with AsyncClient(dispatch=dispatch) as client:
.... |
@dalf - That's a really useful (surprising) bit of feedback, thanks! (And yes, you've got the right approach there, but make sure you're pinning your dependencies tightly if you're relying on private API!) |
In order to grade TLS certificates with CryptCheck searxstats has to retrieve the certificates. Previously this was done by monkey patching httpx.backends.asyncio.AsyncioBackend. The backend parameter for AsyncClient has however been removed in httpx 0.12.0[1]. Since monkey patching private APIs isn't a good idea anyway this commit instead monkey patches the public API of the ssl.SSLContext class of the standard library. [1]: encode/httpx#782 Fixes searxng#89.
In order to grade TLS certificates with CryptCheck searxstats has to retrieve the certificates. Previously this was done by monkey patching httpx.backends.asyncio.AsyncioBackend. The backend parameter for AsyncClient has however been removed in httpx 0.12.0[1]. Since monkey patching private APIs isn't a good idea anyway this commit instead monkey patches the public API of the ssl.SSLContext class of the standard library. [1]: encode/httpx#782 Fixes searxng#89.
In order to grade TLS certificates with CryptCheck searxstats has to retrieve the certificates. Previously this was done by monkey patching httpx.backends.asyncio.AsyncioBackend. The backend parameter for AsyncClient has however been removed in httpx 0.12.0[1]. Since monkey patching private APIs isn't a good idea anyway this commit instead monkey patches the public API of the ssl.SSLContext class of the standard library. [1]: encode/httpx#782 Fixes searxng#89.
Now that we have async autodetection, I think we ought to consider dropping the
backend
argument fromAsyncClient.__init__(...)
, since it's not really required.If anything it'd be better to find out if/when there are any cases that
sniffio
isn't able to correctly detect, and fix them, rather than having users be able to flick an override switch.(It'd also potentially make it easier to have a clear split if we wanted to factor the dispatch out into an entirely independant package at some point, since we'd want the backend implementations to reside in the core networking package, rather than in
httpx
.)The text was updated successfully, but these errors were encountered: