Skip to content
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

Standalone create_ssl_context() function? #983

Closed
tomchristie opened this issue May 22, 2020 · 1 comment
Closed

Standalone create_ssl_context() function? #983

tomchristie opened this issue May 22, 2020 · 1 comment
Labels
enhancement New feature or request
Milestone

Comments

@tomchristie
Copy link
Member

Now that we've got a nicely spec'ed Transport API we can give our users some pretty neat flexibility, but I think there's also one place where we've maybe got a gap we'd like to plug?...

Something that's important for us is to be able to easily demonstrate to our users how to drop down to lower levels of abstraction in the API when needed, for example it'd be really helpful how to instantiate a client directly with an httpcore connection pool...

transport = httpcore.AsyncConnectionPool(...)
client = httpx.AsyncClient(transport=transport)

That's really valuable because it helps an understanding of how the pieces fit together, and also allows us to do stuff like add some low-level connection options on httpcore, without necessarily having to expose those all the way through to httpx. (Eg encode/httpcore#88)

However, the one bit that's missing is that there currently isn't any convenient way for our users to generate an appropriately configured SSLContext without digging into the gnarly details.

I think we might well want to expose a stand alone function to provide users with our "generate an SSL context" functionality, like so...

ssl_context = httpx.create_ssl_context()  # Accepts the standard 'verify', 'cert', trust_env' arguments.

Which then gives our users everything they need to directly plug in a properly configured httpcore connection pool...

ssl_context = httpx.create_ssl_context()
transport = httpcore.AsyncConnectionPool(ssl_context=ssl_context)
client = httpx.AsyncClient(transport=transport)

Implementation-wise this'd just be...

def create_ssl_context(...):
    return SSLConfig(...).ssl_context

And then expose the function at the top-level init.

Incidentally I think our SSLConfig instances our now a bit of a vestige of past designs, and we could probably internally use the same create_ssl_context inside the client implementation, rather than hanging on to the intermediary config instance.

@florimondmanca
Copy link
Member

I think this should have been closed by #996? :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants