1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Fix ssl context being recreated frequently in httpx (#89932)

* Fix ssl context being created every time in httpx

* its expensive, only do it once
This commit is contained in:
J. Nick Koston
2023-03-18 23:13:48 -10:00
committed by GitHub
parent 0e7bd401f2
commit 87264d219a
3 changed files with 12 additions and 2 deletions

View File

@@ -16,6 +16,15 @@ def client_context() -> ssl.SSLContext:
return ssl.create_default_context(purpose=ssl.Purpose.SERVER_AUTH, cafile=cafile)
# Create this only once and reuse it
_DEFAULT_SSL_CONTEXT = client_context()
def get_default_context() -> ssl.SSLContext:
"""Return the default SSL context."""
return _DEFAULT_SSL_CONTEXT
def server_context_modern() -> ssl.SSLContext:
"""Return an SSL context following the Mozilla recommendations.