@@ -28,21 +28,35 @@ def __init__(self, *args, **kwargs):
2828 #: A mapping between HTTP netlocs and ``HTTP20Connection`` objects.
2929 self .connections = {}
3030
31- def get_connection (self , host , port , scheme ):
31+ def get_connection (self , host , port , scheme , cert = None ):
3232 """
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.
3535 """
3636 secure = (scheme == 'https' )
3737
3838 if port is None : # pragma: no cover
3939 port = 80 if not secure else 443
4040
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+
4154 try :
42- conn = self .connections [(host , port , scheme )]
55+ conn = self .connections [(host , port , scheme , cert )]
4356 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
4660
4761 return conn
4862
@@ -51,8 +65,8 @@ def send(self, request, stream=False, **kwargs):
5165 Sends a HTTP message to the server.
5266 """
5367 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' ) )
5670
5771 # Build the selector.
5872 selector = parsed .path
0 commit comments