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