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 88dce9d commit c2006b6
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/requests/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,19 @@ 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
has_custom_pool_kwargs = getattr(poolmanager, "connection_pool_kw", False)

cert_reqs = "CERT_REQUIRED"
if verify is False:
cert_reqs = "CERT_NONE"
elif verify is True:
elif verify is True and not has_custom_pool_kwargs:
pool_kwargs["ssl_context"] = _preloaded_ssl_context
elif isinstance(verify, str):
if not os.path.isdir(verify):
Expand Down Expand Up @@ -391,7 +394,9 @@ def get_connection_with_tls_context(self, request, verify, proxies=None, cert=No
"""
proxy = select_proxy(request.url, proxies)
try:
host_params, pool_kwargs = _urllib3_request_context(request, verify, cert)
host_params, pool_kwargs = _urllib3_request_context(
request, verify, cert, self.poolmanager
)
except ValueError as e:
raise InvalidURL(e, request=request)
if proxy:
Expand Down

0 comments on commit c2006b6

Please sign in to comment.