Skip to content
This repository was archived by the owner on Jan 13, 2021. It is now read-only.

Commit 53b22fa

Browse files
Issue 249: Only initialise the global SSL context if one wasn't manually specified when creating the connection. Fixes exceptions if the cert.pem file included with the hyper package isn't included in a distribution (such as a generated exe)
1 parent da1e8b6 commit 53b22fa

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

hyper/tls.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,16 @@ def wrap_socket(sock, server_hostname, ssl_context=None, force_proto=None):
2929
A vastly simplified SSL wrapping function. We'll probably extend this to
3030
do more things later.
3131
"""
32-
global _context
33-
34-
# create the singleton SSLContext we use
35-
if _context is None: # pragma: no cover
36-
_context = init_context()
37-
38-
# if an SSLContext is provided then use it instead of default context
39-
_ssl_context = ssl_context or _context
32+
if ssl_context:
33+
# if an SSLContext is provided then use it instead of default context
34+
_ssl_context = ssl_context
35+
else:
36+
global _context
37+
38+
# create the singleton SSLContext we use
39+
if _context is None: # pragma: no cover
40+
_context = init_context()
41+
_ssl_context = _context
4042

4143
# the spec requires SNI support
4244
ssl_sock = _ssl_context.wrap_socket(sock, server_hostname=server_hostname)

0 commit comments

Comments
 (0)