Home / Class/ HTTPAdapter Class — requests Architecture

HTTPAdapter Class — requests Architecture

Architecture documentation for the HTTPAdapter class in adapters.py from the requests codebase.

Entity Profile

Dependency Diagram

graph TD
  5fdf5d52_8295_768a_e20f_c6cefb721b91["HTTPAdapter"]
  3115448a_c02d_7a97_aab5_38326ba6f5ae["BaseAdapter"]
  5fdf5d52_8295_768a_e20f_c6cefb721b91 -->|extends| 3115448a_c02d_7a97_aab5_38326ba6f5ae
  8cafec3a_816a_3b74_357a_0167321e5d19["adapters.py"]
  5fdf5d52_8295_768a_e20f_c6cefb721b91 -->|defined in| 8cafec3a_816a_3b74_357a_0167321e5d19
  22d5de8c_9d85_20f5_c3fb_f4c08e8c2ef8["__init__()"]
  5fdf5d52_8295_768a_e20f_c6cefb721b91 -->|method| 22d5de8c_9d85_20f5_c3fb_f4c08e8c2ef8
  cfc0899f_8a4a_47d1_440a_30bbe9d76903["__getstate__()"]
  5fdf5d52_8295_768a_e20f_c6cefb721b91 -->|method| cfc0899f_8a4a_47d1_440a_30bbe9d76903
  216aa9d4_1168_8f0b_3016_d617765a2194["__setstate__()"]
  5fdf5d52_8295_768a_e20f_c6cefb721b91 -->|method| 216aa9d4_1168_8f0b_3016_d617765a2194
  ae70d91c_f99f_b4f2_d044_c4472b35bbe0["init_poolmanager()"]
  5fdf5d52_8295_768a_e20f_c6cefb721b91 -->|method| ae70d91c_f99f_b4f2_d044_c4472b35bbe0
  4e2f0f8e_636e_37d3_f714_243f18338137["proxy_manager_for()"]
  5fdf5d52_8295_768a_e20f_c6cefb721b91 -->|method| 4e2f0f8e_636e_37d3_f714_243f18338137
  f3317fc3_a2fa_ce2a_bb1a_4f53b0443c40["cert_verify()"]
  5fdf5d52_8295_768a_e20f_c6cefb721b91 -->|method| f3317fc3_a2fa_ce2a_bb1a_4f53b0443c40
  7086c4f7_aa89_192d_ccbb_8bfa981ed237["build_response()"]
  5fdf5d52_8295_768a_e20f_c6cefb721b91 -->|method| 7086c4f7_aa89_192d_ccbb_8bfa981ed237
  9e25d4cd_58ba_4762_6222_2cc3ce1b67bb["build_connection_pool_key_attributes()"]
  5fdf5d52_8295_768a_e20f_c6cefb721b91 -->|method| 9e25d4cd_58ba_4762_6222_2cc3ce1b67bb
  b63a634d_66d8_29cd_773b_da0e87ccd411["get_connection_with_tls_context()"]
  5fdf5d52_8295_768a_e20f_c6cefb721b91 -->|method| b63a634d_66d8_29cd_773b_da0e87ccd411
  a177b992_27e6_4822_1c3a_48567aa04e20["get_connection()"]
  5fdf5d52_8295_768a_e20f_c6cefb721b91 -->|method| a177b992_27e6_4822_1c3a_48567aa04e20
  fec2b34c_7706_17c1_1beb_b260bd1e72e6["close()"]
  5fdf5d52_8295_768a_e20f_c6cefb721b91 -->|method| fec2b34c_7706_17c1_1beb_b260bd1e72e6
  19bcbaca_551c_4599_bbfe_015fc1d38ffa["request_url()"]
  5fdf5d52_8295_768a_e20f_c6cefb721b91 -->|method| 19bcbaca_551c_4599_bbfe_015fc1d38ffa

Relationship Graph

Source Code

src/requests/adapters.py lines 145–698

class HTTPAdapter(BaseAdapter):
    """The built-in HTTP Adapter for urllib3.

    Provides a general-case interface for Requests sessions to contact HTTP and
    HTTPS urls by implementing the Transport Adapter interface. This class will
    usually be created by the :class:`Session <Session>` class under the
    covers.

    :param pool_connections: The number of urllib3 connection pools to cache.
    :param pool_maxsize: The maximum number of connections to save in the pool.
    :param max_retries: The maximum number of retries each connection
        should attempt. Note, this applies only to failed DNS lookups, socket
        connections and connection timeouts, never to requests where data has
        made it to the server. By default, Requests does not retry failed
        connections. If you need granular control over the conditions under
        which we retry a request, import urllib3's ``Retry`` class and pass
        that instead.
    :param pool_block: Whether the connection pool should block for connections.

    Usage::

      >>> import requests
      >>> s = requests.Session()
      >>> a = requests.adapters.HTTPAdapter(max_retries=3)
      >>> s.mount('http://', a)
    """

    __attrs__ = [
        "max_retries",
        "config",
        "_pool_connections",
        "_pool_maxsize",
        "_pool_block",
    ]

    def __init__(
        self,
        pool_connections=DEFAULT_POOLSIZE,
        pool_maxsize=DEFAULT_POOLSIZE,
        max_retries=DEFAULT_RETRIES,
        pool_block=DEFAULT_POOLBLOCK,
    ):
        if max_retries == DEFAULT_RETRIES:
            self.max_retries = Retry(0, read=False)
        else:
            self.max_retries = Retry.from_int(max_retries)
        self.config = {}
        self.proxy_manager = {}

        super().__init__()

        self._pool_connections = pool_connections
        self._pool_maxsize = pool_maxsize
        self._pool_block = pool_block

        self.init_poolmanager(pool_connections, pool_maxsize, block=pool_block)

    def __getstate__(self):
        return {attr: getattr(self, attr, None) for attr in self.__attrs__}

    def __setstate__(self, state):
        # Can't handle by adding 'proxy_manager' to self.__attrs__ because
        # self.poolmanager uses a lambda function, which isn't pickleable.
        self.proxy_manager = {}
        self.config = {}

        for attr, value in state.items():
            setattr(self, attr, value)

        self.init_poolmanager(
            self._pool_connections, self._pool_maxsize, block=self._pool_block
        )

    def init_poolmanager(
        self, connections, maxsize, block=DEFAULT_POOLBLOCK, **pool_kwargs
    ):
        """Initializes a urllib3 PoolManager.

        This method should not be called from user code, and is only
        exposed for use when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.

Domain

Extends

Frequently Asked Questions

What is the HTTPAdapter class?
HTTPAdapter is a class in the requests codebase, defined in src/requests/adapters.py.
Where is HTTPAdapter defined?
HTTPAdapter is defined in src/requests/adapters.py at line 145.
What does HTTPAdapter extend?
HTTPAdapter extends BaseAdapter.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free