psf / requests

A simple, yet elegant, HTTP library.
https://requests.readthedocs.io/en/latest/
Apache License 2.0
52.19k stars 9.33k forks source link

Documentation of what to override when using custom adapter #6776

Closed achapkowski closed 3 months ago

achapkowski commented 3 months ago

Hello,

I wish to use a custom adapter that I can use to access servers with old and expired certificates so I can automate the updating of the SSL certs.

I have the following:

###########################################################################
class TruststoreAdapter(HTTPAdapter):
    """An adapter for requests.  This supplies the a custom ssl_context to a set of requests."""

    custom_context: truststore.SSLContext | ssl.SSLContext = None

    def __init__(
        self,
        pool_connections=DEFAULT_POOLSIZE,
        pool_maxsize=DEFAULT_POOLSIZE,
        max_retries=DEFAULT_RETRIES,
        pool_block=DEFAULT_POOLBLOCK,
        ssl_context: truststore.SSLContext | ssl.SSLContext | None = None,
    ):
        self.custom_context = ssl_context

        super().__init__(
            pool_connections=pool_connections,
            pool_maxsize=pool_maxsize,
            max_retries=max_retries,
            pool_block=pool_block,
        )

    # ---------------------------------------------------------------------
    def __str__(self) -> str:
        return f"< {self.__class__.__name__} >"

    # ---------------------------------------------------------------------
    def __repr__(self) -> str:
        return f"< {self.__class__.__name__} >"

    # ---------------------------------------------------------------------
    def init_poolmanager(self, connections, maxsize, block=False):
        ctx = self.custom_context
        return super().init_poolmanager(connections, maxsize, block, ssl_context=ctx)

Where the SSL Context is defined as:

ssl_context: truststore.SSLContext = truststore.SSLContext()
ssl_context.check_hostname = False
ssl_context.verify_mode = 0 # No check
github-actions[bot] commented 3 months ago

As described in the template, Requests is not accepting feature requests