15
15
HTTPAdapter = object
16
16
17
17
from hyper .common .connection import HTTPConnection
18
- from hyper .compat import urlparse
18
+ from hyper .compat import urlparse , ssl
19
19
from hyper .tls import init_context
20
20
21
21
@@ -29,7 +29,7 @@ def __init__(self, *args, **kwargs):
29
29
#: A mapping between HTTP netlocs and ``HTTP20Connection`` objects.
30
30
self .connections = {}
31
31
32
- def get_connection (self , host , port , scheme , cert = None ):
32
+ def get_connection (self , host , port , scheme , cert = None , verify = True ):
33
33
"""
34
34
Gets an appropriate HTTP/2 connection object based on
35
35
host/port/scheme/cert tuples.
@@ -40,22 +40,29 @@ def get_connection(self, host, port, scheme, cert=None):
40
40
port = 80 if not secure else 443
41
41
42
42
ssl_context = None
43
- if cert is not None :
43
+ if not verify :
44
+ verify = False
44
45
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 )
45
52
46
53
try :
47
- conn = self .connections [(host , port , scheme , cert )]
54
+ conn = self .connections [(host , port , scheme , cert , verify )]
48
55
except KeyError :
49
56
conn = HTTPConnection (
50
57
host ,
51
58
port ,
52
59
secure = secure ,
53
60
ssl_context = ssl_context )
54
- self .connections [(host , port , scheme , cert )] = conn
61
+ self .connections [(host , port , scheme , cert , verify )] = conn
55
62
56
63
return conn
57
64
58
- def send (self , request , stream = False , cert = None , ** kwargs ):
65
+ def send (self , request , stream = False , cert = None , verify = True , ** kwargs ):
59
66
"""
60
67
Sends a HTTP message to the server.
61
68
"""
@@ -64,7 +71,8 @@ def send(self, request, stream=False, cert=None, **kwargs):
64
71
parsed .hostname ,
65
72
parsed .port ,
66
73
parsed .scheme ,
67
- cert = cert )
74
+ cert = cert ,
75
+ verify = verify )
68
76
69
77
# Build the selector.
70
78
selector = parsed .path
0 commit comments