MCPcopy
hub / github.com/psf/requests / rebuild_proxies

Method rebuild_proxies

src/requests/sessions.py:334–368  ·  view source on GitHub ↗

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

(
        self,
        prepared_request: PreparedRequest,
        proxies: dict[str, str] | None,
    )

Source from the content-addressed store, hash-verified

332 prepared_request.prepare_auth(new_auth)
333
334 def rebuild_proxies(
335 self,
336 prepared_request: PreparedRequest,
337 proxies: dict[str, str] | None,
338 ) -> dict[str, str]:
339 """This method re-evaluates the proxy configuration by considering the
340 environment variables. If we are redirected to a URL covered by
341 NO_PROXY, we strip the proxy configuration. Otherwise, we set missing
342 proxy keys for this URL (in case they were stripped by a previous
343 redirect).
344
345 This method also replaces the Proxy-Authorization header where
346 necessary.
347
348 :rtype: dict
349 """
350 assert _is_prepared(prepared_request)
351 headers = prepared_request.headers
352 scheme = urlparse(prepared_request.url).scheme
353 new_proxies = resolve_proxies(prepared_request, proxies, self.trust_env)
354
355 if "Proxy-Authorization" in headers:
356 del headers["Proxy-Authorization"]
357
358 try:
359 username, password = get_auth_from_url(new_proxies[scheme])
360 except KeyError:
361 username, password = None, None
362
363 # urllib3 handles proxy authorization for us in the standard adapter.
364 # Avoid appending this to TLS tunneled requests where it may be leaked.
365 if not scheme.startswith("https") and username and password:
366 headers["Proxy-Authorization"] = _basic_auth_str(username, password)
367
368 return new_proxies
369
370 def rebuild_method(
371 self, prepared_request: PreparedRequest, response: Response

Calls 3

resolve_proxiesFunction · 0.85
get_auth_from_urlFunction · 0.85
_basic_auth_strFunction · 0.85