Skip to content

Commit

Permalink
Don't use default SSLContext with custom poolmanager kwargs
Browse files Browse the repository at this point in the history
  • Loading branch information
nateprewitt committed May 24, 2024
1 parent 6badbac commit b1d73dd
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/requests/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,20 @@ def _urllib3_request_context(
request: "PreparedRequest",
verify: "bool | str | None",
client_cert: "typing.Tuple[str, str] | str | None",
poolmanager: "PoolManager",
) -> "(typing.Dict[str, typing.Any], typing.Dict[str, typing.Any])":
host_params = {}
pool_kwargs = {}
parsed_request_url = urlparse(request.url)
scheme = parsed_request_url.scheme.lower()
port = parsed_request_url.port
poolmanager_kwargs = getattr(poolmanager, "connection_pool_kw", {})
has_poolmanager_ssl_context = poolmanager_kwargs.get("ssl_context")

cert_reqs = "CERT_REQUIRED"
if verify is False:
cert_reqs = "CERT_NONE"
elif verify is True:
elif verify is True and not has_poolmanager_ssl_context:
pool_kwargs["ssl_context"] = _preloaded_ssl_context
elif isinstance(verify, str):
if not os.path.isdir(verify):
Expand Down Expand Up @@ -423,7 +427,7 @@ def build_connection_pool_key_attributes(self, request, verify, cert=None):
portion of the Pool Key including scheme, hostname, and port. The
second is a dictionary of SSLContext related parameters.
"""
return _urllib3_request_context(request, verify, cert)
return _urllib3_request_context(request, verify, cert, self.poolmanager)

def get_connection_with_tls_context(self, request, verify, proxies=None, cert=None):
"""Returns a urllib3 connection for the given request and TLS settings.
Expand Down

0 comments on commit b1d73dd

Please sign in to comment.