Home / Function/ rebuild_proxies() — requests Function Reference

rebuild_proxies() — requests Function Reference

Architecture documentation for the rebuild_proxies() function in sessions.py from the requests codebase.

Function python CoreAPI SessionLifecycle calls 3 called by 1

Entity Profile

Dependency Diagram

graph TD
  37e21bd7_763f_f217_e84e_39590f4b9478["rebuild_proxies()"]
  29cd946c_8c0d_e37c_acb9_dfb2b83bf42b["SessionRedirectMixin"]
  37e21bd7_763f_f217_e84e_39590f4b9478 -->|defined in| 29cd946c_8c0d_e37c_acb9_dfb2b83bf42b
  cbf6862f_d124_817f_3342_f1142c276f25["resolve_redirects()"]
  cbf6862f_d124_817f_3342_f1142c276f25 -->|calls| 37e21bd7_763f_f217_e84e_39590f4b9478
  78f79a1e_c8bc_1d85_cefa_cf45d6efb42a["resolve_proxies()"]
  37e21bd7_763f_f217_e84e_39590f4b9478 -->|calls| 78f79a1e_c8bc_1d85_cefa_cf45d6efb42a
  1a78d81a_ddf9_f329_5c88_eabcf1bdece2["get_auth_from_url()"]
  37e21bd7_763f_f217_e84e_39590f4b9478 -->|calls| 1a78d81a_ddf9_f329_5c88_eabcf1bdece2
  fa72bb6a_120a_ce88_fe4e_28d8c4d3b882["_basic_auth_str()"]
  37e21bd7_763f_f217_e84e_39590f4b9478 -->|calls| fa72bb6a_120a_ce88_fe4e_28d8c4d3b882
  style 37e21bd7_763f_f217_e84e_39590f4b9478 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/requests/sessions.py lines 303–332

    def rebuild_proxies(self, prepared_request, proxies):
        """This method re-evaluates the proxy configuration by considering the
        environment variables. If we are redirected to a URL covered by
        NO_PROXY, we strip the proxy configuration. Otherwise, we set missing
        proxy keys for this URL (in case they were stripped by a previous
        redirect).

        This method also replaces the Proxy-Authorization header where
        necessary.

        :rtype: dict
        """
        headers = prepared_request.headers
        scheme = urlparse(prepared_request.url).scheme
        new_proxies = resolve_proxies(prepared_request, proxies, self.trust_env)

        if "Proxy-Authorization" in headers:
            del headers["Proxy-Authorization"]

        try:
            username, password = get_auth_from_url(new_proxies[scheme])
        except KeyError:
            username, password = None, None

        # urllib3 handles proxy authorization for us in the standard adapter.
        # Avoid appending this to TLS tunneled requests where it may be leaked.
        if not scheme.startswith("https") and username and password:
            headers["Proxy-Authorization"] = _basic_auth_str(username, password)

        return new_proxies

Domain

Subdomains

Frequently Asked Questions

What does rebuild_proxies() do?
rebuild_proxies() is a function in the requests codebase, defined in src/requests/sessions.py.
Where is rebuild_proxies() defined?
rebuild_proxies() is defined in src/requests/sessions.py at line 303.
What does rebuild_proxies() call?
rebuild_proxies() calls 3 function(s): _basic_auth_str, get_auth_from_url, resolve_proxies.
What calls rebuild_proxies()?
rebuild_proxies() is called by 1 function(s): resolve_redirects.

Analyze Your Own Codebase

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

Try Supermodel Free