From: Tom Christie Date: Mon, 19 Aug 2019 19:19:40 +0000 (+0100) Subject: Use correct protocol idents when loading ssl context X-Git-Tag: 0.7.2~19^2~7^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7fea0723e2e6256472b12c12b2e95f2fa49c8a83;p=thirdparty%2Fhttpx.git Use correct protocol idents when loading ssl context --- diff --git a/httpx/dispatch/connection.py b/httpx/dispatch/connection.py index 48271763..ac06d62d 100644 --- a/httpx/dispatch/connection.py +++ b/httpx/dispatch/connection.py @@ -1,5 +1,6 @@ import functools import typing +import ssl from ..concurrency import AsyncioBackend from ..config import ( @@ -73,12 +74,7 @@ class HTTPConnection(AsyncDispatcher): host = self.origin.host port = self.origin.port - # Run the SSL loading in a threadpool, since it makes disk accesses. - ssl_context = ( - await self.backend.run_in_threadpool(ssl.load_ssl_context) - if self.origin.is_ssl - else None - ) + ssl_context = await self.get_ssl_context(ssl, protocols) if self.release_func is None: on_release = None @@ -97,6 +93,13 @@ class HTTPConnection(AsyncDispatcher): reader, writer, self.backend, on_release=on_release ) + async def get_ssl_context(self, ssl: SSLConfig, protocols: ProtocolConfig) -> typing.Optional[ssl.SSLContext]: + if not self.origin.is_ssl: + return None + + # Run the SSL loading in a threadpool, since it may makes disk accesses. + return await self.backend.run_in_threadpool(ssl.load_ssl_context, protocols) + async def close(self) -> None: if self.h2_connection is not None: await self.h2_connection.close()