]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Use correct protocol idents when loading ssl context
authorTom Christie <tom@tomchristie.com>
Mon, 19 Aug 2019 19:19:40 +0000 (20:19 +0100)
committerTom Christie <tom@tomchristie.com>
Mon, 19 Aug 2019 19:19:40 +0000 (20:19 +0100)
httpx/dispatch/connection.py

index 48271763967f4742c2cea10ca6821b199498b214..ac06d62d60f8862de939d3bd181e034b34405771 100644 (file)
@@ -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()