def rebuild_proxies(self, prepared_request, proxies):
headers = prepared_request.headers<EOL>url = prepared_request.url<EOL>scheme = urlparse(url).scheme<EOL>new_proxies = proxies.copy() if proxies is not None else {}<EOL>if self.trust_env and not should_bypass_proxies(url):<EOL><INDENT>environ_proxies = get_environ_proxies(url)<EOL>proxy = environ_proxies.get(scheme)<EOL>if proxy:<EOL><INDENT>new_proxies.setdefault(scheme, environ_proxies[scheme])<EOL><DEDENT><DEDENT>if '<STR_LIT>' in headers:<EOL><INDENT>del headers['<STR_LIT>']<EOL><DEDENT>try:<EOL><INDENT>username, password = get_auth_from_url(new_proxies[scheme])<EOL><DEDENT>except KeyError:<EOL><INDENT>username, password = None, None<EOL><DEDENT>if username and password:<EOL><INDENT>headers['<STR_LIT>'] = _basic_auth_str(username, password)<EOL><DEDENT>return new_proxies<EOL>
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.