prepared_request._cookies.update(self.cookies)
prepared_request.prepare_cookies(prepared_request._cookies)
+ # If we get redirected to a new host, we should strip out any
+ # authentication headers.
+ original_parsed = urlparse(resp.request.url)
+ redirect_parsed = urlparse(url)
+
+ if original_parsed.hostname != redirect_parsed.hostname:
+ try:
+ del headers['Authorization']
+ except KeyError:
+ pass
+
+ # However, .netrc might have more auth for us. Let's get it if it
+ # does.
+ new_auth = get_netrc_auth(url)
+ if new_auth is not None:
+ prepared_request.prepare_auth(new_auth)
+
resp = self.send(
prepared_request,
stream=stream,