9
9
import os .path
10
10
import socket # noqa: F401
11
11
import typing
12
+ import warnings
12
13
13
14
from urllib3 .exceptions import ClosedPoolError , ConnectTimeoutError
14
15
from urllib3 .exceptions import HTTPError as _HTTPError
@@ -374,10 +375,20 @@ def build_response(self, req, resp):
374
375
375
376
return response
376
377
377
- def _get_connection (self , request , verify , proxies = None , cert = None ):
378
- # Replace the existing get_connection without breaking things and
379
- # ensure that TLS settings are considered when we interact with
380
- # urllib3 HTTP Pools
378
+ def get_connection_with_tls_context (self , request , verify , proxies = None , cert = None ):
379
+ """Returns a urllib3 connection for the given request and TLS settings.
380
+ This should not be called from user code, and is only exposed for use
381
+ when subclassing the :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
382
+
383
+ :param request: The :class:`PreparedRequest <PreparedRequest>` object
384
+ to be sent over the connection.
385
+ :param verify: Either a boolean, in which case it controls whether
386
+ we verify the server's TLS certificate, or a string, in which case it
387
+ must be a path to a CA bundle to use.
388
+ :param proxies: (optional) The proxies dictionary to apply to the request.
389
+ :param cert: (optional) Any user-provided SSL certificate to be trusted.
390
+ :rtype: urllib3.ConnectionPool
391
+ """
381
392
proxy = select_proxy (request .url , proxies )
382
393
try :
383
394
host_params , pool_kwargs = _urllib3_request_context (request , verify , cert )
@@ -404,14 +415,26 @@ def _get_connection(self, request, verify, proxies=None, cert=None):
404
415
return conn
405
416
406
417
def get_connection (self , url , proxies = None ):
407
- """Returns a urllib3 connection for the given URL. This should not be
418
+ """DEPRECATED: Users should move to `get_connection_with_tls_context`
419
+ for all subclasses of HTTPAdapter using Requests>=2.32.2.
420
+
421
+ Returns a urllib3 connection for the given URL. This should not be
408
422
called from user code, and is only exposed for use when subclassing the
409
423
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
410
424
411
425
:param url: The URL to connect to.
412
426
:param proxies: (optional) A Requests-style dictionary of proxies used on this request.
413
427
:rtype: urllib3.ConnectionPool
414
428
"""
429
+ warnings .warn (
430
+ (
431
+ "`get_connection` has been deprecated in favor of "
432
+ "`get_connection_with_tls_context`. Custom HTTPAdapter subclasses "
433
+ "will need to migrate for Requests>=2.32.2. Please see "
434
+ "https://github.com/psf/requests/pull/6710 for more details."
435
+ ),
436
+ DeprecationWarning ,
437
+ )
415
438
proxy = select_proxy (url , proxies )
416
439
417
440
if proxy :
@@ -529,7 +552,9 @@ def send(
529
552
"""
530
553
531
554
try :
532
- conn = self ._get_connection (request , verify , proxies = proxies , cert = cert )
555
+ conn = self .get_connection_with_tls_context (
556
+ request , verify , proxies = proxies , cert = cert
557
+ )
533
558
except LocationValueError as e :
534
559
raise InvalidURL (e , request = request )
535
560
0 commit comments