Skip to content

Commit 3b87121

Browse files
committed
tweak how we create session and mount adapter
1 parent b4ec8a6 commit 3b87121

File tree

1 file changed

+6
-14
lines changed
  • datadog_checks_base/datadog_checks/base/utils

1 file changed

+6
-14
lines changed

datadog_checks_base/datadog_checks/base/utils/http.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -456,12 +456,9 @@ def _request(self, method, url, options):
456456
for hook in self.request_hooks:
457457
stack.enter_context(hook())
458458

459-
new_tls_config = self._get_new_tls_config(url, new_options)
460-
if persist:
461-
session = self.session
462-
self._mount_https_adapter(session, new_tls_config)
463-
else:
464-
session = self._create_session(tls_config=new_tls_config)
459+
session = self.session if persist else self._create_session()
460+
if url.startswith('https'):
461+
self._mount_https_adapter(session, ChainMap(get_tls_config_from_options(new_options), self.tls_config))
465462
request_method = getattr(session, method)
466463

467464
if self.auth_token_handler:
@@ -503,14 +500,9 @@ def make_request_aia_chasing(self, request_method, method, url, new_options, per
503500
certs = self.fetch_intermediate_certs(hostname, port)
504501
if not certs:
505502
raise e
506-
new_ca_certs = {'tls_intermediate_ca_certs': certs}
507-
new_tls_config = self.tls_config.copy()
508-
new_tls_config.update(new_ca_certs)
509-
if not persist:
510-
session = self._create_session(new_tls_config)
511-
else:
512-
session = self.session
513-
self._mount_https_adapter(session, new_tls_config)
503+
session = self.session if persist else self._create_session()
504+
if parsed_url.scheme == "https":
505+
self._mount_https_adapter(session, ChainMap({'tls_intermediate_ca_certs': certs}, self.tls_config))
514506
request_method = getattr(session, method)
515507
response = request_method(url, **new_options)
516508
return response

0 commit comments

Comments
 (0)