def rebuild_auth(self, prepared_request, response):
headers = prepared_request.headers<EOL>url = prepared_request.url<EOL>if '<STR_LIT>' in headers:<EOL><INDENT>original_parsed = urlparse(response.request.url)<EOL>redirect_parsed = urlparse(url)<EOL>if (original_parsed.hostname != redirect_parsed.hostname):<EOL><INDENT>del headers['<STR_LIT>']<EOL><DEDENT><DEDENT>new_auth = get_netrc_auth(url) if self.trust_env else None<EOL>if new_auth is not None:<EOL><INDENT>prepared_request.prepare_auth(new_auth)<EOL><DEDENT>return<EOL>
When being redirected we may want to strip authentication from the
request to avoid leaking credentials. This method intelligently removes
and reapplies authentication where possible to avoid credential loss.