1515 HTTPAdapter = object
1616
1717from hyper .common .connection import HTTPConnection
18- from hyper .compat import urlparse
18+ from hyper .compat import urlparse , ssl
1919from hyper .tls import init_context
2020
2121
@@ -29,7 +29,7 @@ def __init__(self, *args, **kwargs):
2929 #: A mapping between HTTP netlocs and ``HTTP20Connection`` objects.
3030 self .connections = {}
3131
32- def get_connection (self , host , port , scheme , cert = None ):
32+ def get_connection (self , host , port , scheme , cert = None , verify = True ):
3333 """
3434 Gets an appropriate HTTP/2 connection object based on
3535 host/port/scheme/cert tuples.
@@ -40,22 +40,29 @@ def get_connection(self, host, port, scheme, cert=None):
4040 port = 80 if not secure else 443
4141
4242 ssl_context = None
43- if cert is not None :
43+ if not verify :
44+ verify = False
4445 ssl_context = init_context (cert = cert )
46+ ssl_context .check_hostname = False
47+ ssl_context .verify_mode = ssl .CERT_NONE
48+ elif verify is True and cert is not None :
49+ ssl_context = init_context (cert = cert )
50+ elif verify is not True :
51+ ssl_context = init_context (cert_path = verify , cert = cert )
4552
4653 try :
47- conn = self .connections [(host , port , scheme , cert )]
54+ conn = self .connections [(host , port , scheme , cert , verify )]
4855 except KeyError :
4956 conn = HTTPConnection (
5057 host ,
5158 port ,
5259 secure = secure ,
5360 ssl_context = ssl_context )
54- self .connections [(host , port , scheme , cert )] = conn
61+ self .connections [(host , port , scheme , cert , verify )] = conn
5562
5663 return conn
5764
58- def send (self , request , stream = False , cert = None , ** kwargs ):
65+ def send (self , request , stream = False , cert = None , verify = True , ** kwargs ):
5966 """
6067 Sends a HTTP message to the server.
6168 """
@@ -64,7 +71,8 @@ def send(self, request, stream=False, cert=None, **kwargs):
6471 parsed .hostname ,
6572 parsed .port ,
6673 parsed .scheme ,
67- cert = cert )
74+ cert = cert ,
75+ verify = verify )
6876
6977 # Build the selector.
7078 selector = parsed .path
0 commit comments