@@ -153,9 +153,10 @@ class RequestsWrapper(object):
153
153
'request_size' ,
154
154
'tls_protocols_allowed' ,
155
155
'tls_ciphers_allowed' ,
156
+ 'tls_context' ,
156
157
)
157
158
158
- def __init__ (self , instance , init_config , remapper = None , logger = None , session = None ):
159
+ def __init__ (self , instance , init_config , remapper = None , logger = None , session = None , tls_context = None ):
159
160
self .logger = logger or LOGGER
160
161
default_fields = dict (STANDARD_FIELDS )
161
162
@@ -348,13 +349,18 @@ def __init__(self, instance, init_config, remapper=None, logger=None, session=No
348
349
self .request_hooks .append (lambda : handle_kerberos_cache (config ['kerberos_cache' ]))
349
350
350
351
ciphers = config .get ('tls_ciphers' )
351
- if ciphers :
352
- if 'ALL' in ciphers :
353
- updated_ciphers = "ALL"
354
- else :
355
- updated_ciphers = ":" .join (ciphers )
352
+ if ciphers is None :
353
+ updated_ciphers = 'ALL'
354
+ self .logger .debug ('No ciphers specified, defaulting to ALL' )
355
+ elif 'ALL' in ciphers :
356
+ updated_ciphers = "ALL"
357
+ else :
358
+ updated_ciphers = ":" .join (ciphers )
356
359
self .tls_ciphers_allowed = updated_ciphers
357
360
361
+ # If a TLS context was provided, use it
362
+ self .tls_context = tls_context
363
+
358
364
def get (self , url , ** options ):
359
365
return self ._request ('get' , url , options )
360
366
@@ -534,14 +540,23 @@ def load_intermediate_certs(self, der_cert, certs):
534
540
535
541
@property
536
542
def session (self ):
537
- # TODO: modify the session object to use the same context and ciphers for all requests
538
543
if self ._session is None :
539
544
self ._session = requests .Session ()
540
545
541
546
# Enables HostHeaderSSLAdapter
542
547
# https://toolbelt.readthedocs.io/en/latest/adapters.html#hostheaderssladapter
543
548
if self .tls_use_host_header :
544
- self ._session .mount ('https://' , _http_utils .HostHeaderSSLAdapter ())
549
+ https_adapter = _http_utils .HostHeaderSSLAdapter ()
550
+ else :
551
+ https_adapter = requests .adapters .HTTPAdapter ()
552
+ # Set the context
553
+ if self .tls_context :
554
+ https_adapter .init_poolmanager (
555
+ connections = self ._session .adapters ['https://' ]._pool_connections ,
556
+ maxsize = self ._session .adapters ['https://' ]._pool_maxsize ,
557
+ ssl_context = self .tls_context ,
558
+ )
559
+ self ._session .mount ('https://' , https_adapter )
545
560
# Enable Unix Domain Socket (UDS) support.
546
561
# See: https://github.com/msabramo/requests-unixsocket
547
562
self ._session .mount ('{}://' .format (UDS_SCHEME ), requests_unixsocket .UnixAdapter ())
0 commit comments