-
-
Notifications
You must be signed in to change notification settings - Fork 997
Description
Checklist
- [x ] I searched the HTTPX documentation but couldn't find what I'm looking for. I looked at:
- [x ] I looked through similar issues on GitHub, but didn't find anything. I looked at:
- [x ] I looked up "How to do ... in HTTPX" on a search engine and didn't find any information.
- I asked the community chat for help but didn't get an answer.
Question
Can I create a httpx.Client with my own ssl.SSLContext or urllib3.contrib.pyopenssl.PyOpenSSLContext instead of passing in cert/key/verify?
Background
I found httpx while looking for requests syntax + asyncio support. It looks like a great project, thanks for all the work you've put into it.
One very oft-asked feature for requests.py was making requests with user-provided SSLContexts 2118. Eventually that was resolved by allowing us to pass SSLContexts to Adapters, then mounting the adapter onto a session. As a real world example, I have used pypki2 and requests_pkcs12 at different times to create Session's from PKCS12/X509 certificates instead of PEM format that I believe vanilla requests and httpx require. There is a requests_pkcs12 author blog post with more background.
My understanding from reading httpx documentation is that a httpx.Client is roughly similar to a requests.Session and the Dispatcher API will be roughly similar to Adapters. @tomchristie mentions configuring an ssl_context in 768 - Dispatcher API but I didn't understand how to use that in practice.
@sethmlarson suggests httpx.Client(verify=ssl_context) in 469, which looked similar to my use-case but not identical. When I tried that with httpx 0.12.1 and 0.13.0.dev, I got TypeError: expected str, bytes or os.PathLike object, not PyOpenSSLContext on Client init.
Thanks.
(courtesy tagging @rashley-iqt (requests_pkcs12) and @gershwinlabs (pypki2) )