@@ -28,21 +28,35 @@ def __init__(self, *args, **kwargs):
28
28
#: A mapping between HTTP netlocs and ``HTTP20Connection`` objects.
29
29
self .connections = {}
30
30
31
- def get_connection (self , host , port , scheme ):
31
+ def get_connection (self , host , port , scheme , cert = None ):
32
32
"""
33
- Gets an appropriate HTTP/2 connection object based on host/port/scheme
34
- tuples.
33
+ Gets an appropriate HTTP/2 connection object based on
34
+ host/port/scheme/cert tuples.
35
35
"""
36
36
secure = (scheme == 'https' )
37
37
38
38
if port is None : # pragma: no cover
39
39
port = 80 if not secure else 443
40
40
41
+ ssl_context = None
42
+
43
+ if cert is not None :
44
+ ssl_context = init_context ()
45
+ try :
46
+ basestring
47
+ except NameError :
48
+ basestring = str
49
+ if not isinstance (cert , basestring ):
50
+ ssl_context .load_cert_chain (cert [0 ], cert [1 ])
51
+ else :
52
+ ssl_context .load_cert_chain (cert )
53
+
41
54
try :
42
- conn = self .connections [(host , port , scheme )]
55
+ conn = self .connections [(host , port , scheme , cert )]
43
56
except KeyError :
44
- conn = HTTPConnection (host , port , secure = secure )
45
- self .connections [(host , port , scheme )] = conn
57
+ conn = HTTPConnection (host , port , secure = secure ,
58
+ ssl_context = ssl_context )
59
+ self .connections [(host , port , scheme , cert )] = conn
46
60
47
61
return conn
48
62
@@ -51,8 +65,8 @@ def send(self, request, stream=False, **kwargs):
51
65
Sends a HTTP message to the server.
52
66
"""
53
67
parsed = urlparse (request .url )
54
-
55
- conn = self . get_connection ( parsed . hostname , parsed . port , parsed . scheme )
68
+ conn = self . get_connection ( parsed . hostname , parsed . port , parsed . scheme ,
69
+ cert = kwargs . get ( 'cert' ) )
56
70
57
71
# Build the selector.
58
72
selector = parsed .path
0 commit comments