diff --git a/README.md b/README.md index 487a53a..e334324 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ This work presents a significantly simplified implementation of `httpx`. * Seriously, a [radically simplified implementation](https://github.com/encode/httpnext/blob/main/src/httpx/_client.py). While still fulfiling the same set of functionality. * A consistent & tightly typed set of HTTP components, with immutability throughout. Includes URLs, Query Parameters, Headers, Form & File interfaces, all of which are suitable for either client side or server side codebases. * A re-engineered [connection pool implementation](https://github.com/encode/httpnext/blob/main/src/httpx/_pool.py), with tighter more obvious concurrency handling. -* The core networking component is simple enough to be directly included. There is no `httpx`/`httpcore` split, and the only hard dependencies here are `h11` and `truststore`. +* The core networking component is simple enough to be directly included. The only hard dependency here is `h11`. * Seperately namespaced packages for `ahttpx` and `httpx`. There is also preliminary work ongoing for httpx *for both client-side and server-side usage*. @@ -75,7 +75,6 @@ Package and dependencies... * httpx * h11 -* truststore --- diff --git a/docs/index.md b/docs/index.md index 6e49bd7..d334f90 100644 --- a/docs/index.md +++ b/docs/index.md @@ -22,7 +22,7 @@ This work insteads presents a significantly simplified implementation of `httpx` * Preliminary work for httpx to support both client-side and server-side usages. * A re-engineered [connection pool implementation](https://github.com/encode/httpx-insiders/blob/main/src/httpx/_pool.py), with tighter more obvious concurrency handling. -* The core networking component is simple enough to be directly included. The only hard dependencies here are `h11` and `truststore`. +* The core networking component is simple enough to be directly included. The only hard dependency here is `h11`. * Seperately namespaced packages for `ahttpx` and `httpx`. There is also preliminary work ongoing for httpx *for both client-side and server-side usage*. @@ -98,7 +98,6 @@ Package and dependencies... * httpx * h11 -* truststore --- @@ -124,4 +123,4 @@ Our credentials to date include authorship of signifcant parts of the Python dev --- -

This provisional design work is not currently licensed for reuse.
— 🦋 —

+

This provisional design work is not currently licensed for reuse.
— 🦋 —

diff --git a/pyproject.toml b/pyproject.toml index 34d6651..fc22742 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,5 +26,4 @@ classifiers = [ ] dependencies = [ "h11==0.*", - "truststore==0.10", ] diff --git a/src/ahttpx/_pool.py b/src/ahttpx/_pool.py index 41c79c6..c7bb7ed 100644 --- a/src/ahttpx/_pool.py +++ b/src/ahttpx/_pool.py @@ -156,8 +156,7 @@ async def open_connection_pool( backend: NetworkBackend | None = None ) -> ConnectionPool: if ssl_context is None: - import truststore - ssl_context = truststore.SSLContext(ssl.PROTOCOL_TLS_CLIENT) + ssl_context = create_default_context() if backend is None: backend = NetworkBackend() @@ -343,8 +342,15 @@ async def open_connection( stream = await backend.connect(host, port) if url.scheme == "https": if ssl_context is None: - import truststore - ssl_context = truststore.SSLContext(ssl.PROTOCOL_TLS_CLIENT) + ssl_context = create_default_context() await stream.start_tls(ssl_context, hostname=hostname) return Connection(stream, url) + + +def create_default_context() -> ssl.SSLContext: + try: + import certifi + except ImportError: + return ssl.create_default_context() + ssl.create_default_context(cafile=certifi.where()) diff --git a/src/httpx/_pool.py b/src/httpx/_pool.py index 5c92eac..50c9ab5 100644 --- a/src/httpx/_pool.py +++ b/src/httpx/_pool.py @@ -156,8 +156,7 @@ def open_connection_pool( backend: NetworkBackend | None = None ) -> ConnectionPool: if ssl_context is None: - import truststore - ssl_context = truststore.SSLContext(ssl.PROTOCOL_TLS_CLIENT) + ssl_context = create_default_context() if backend is None: backend = NetworkBackend() @@ -343,8 +342,15 @@ def open_connection( stream = backend.connect(host, port) if url.scheme == "https": if ssl_context is None: - import truststore - ssl_context = truststore.SSLContext(ssl.PROTOCOL_TLS_CLIENT) + ssl_context = create_default_context() stream.start_tls(ssl_context, hostname=hostname) return Connection(stream, url) + + +def create_default_context() -> ssl.SSLContext: + try: + import certifi + except ImportError: + return ssl.create_default_context() + ssl.create_default_context(cafile=certifi.where())