Skip to content

Standalone create_ssl_context() function? #983

Closed

Description

@lovelydinosaur

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.

Activity

  1. added this to the v1.0 milestone on May 22, 2020
  2. modified the milestones: v1.0, v0.14 on Jul 27, 2020
  3. florimondmanca commented on Jul 30, 2020

    @florimondmanca
    Contributor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions