cleanup shitty code
authorKenneth Reitz <me@kennethreitz.com>
Fri, 31 Jan 2014 17:27:05 +0000 (12:27 -0500)
committerKenneth Reitz <me@kennethreitz.com>
Fri, 31 Jan 2014 17:27:05 +0000 (12:27 -0500)
requests/sessions.py

index ae7390c5b878f27061b1cfdd7e9c3fd8355be69f..de92d5024ecdd9a6b2170bb4d9f8b7bf7f28913e 100644 (file)
@@ -153,22 +153,20 @@ class SessionRedirectMixin(object):
             except KeyError:
                 pass
 
-            extract_cookies_to_jar(prepared_request._cookies,
-                                   prepared_request, resp.raw)
+            extract_cookies_to_jar(prepared_request._cookies, prepared_request, resp.raw)
             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 'Authorization' in headers:
+                # 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 and
-                   'Authorization' in headers):
-                del headers['Authorization']
+                if (original_parsed.hostname != redirect_parsed.hostname):
+                    del headers['Authorization']
 
-            # However, .netrc might have more auth for us. Let's get it if it
-            # does.
+            # .netrc might have more auth for us.
             new_auth = get_netrc_auth(url) if self.trust_env else None
             if new_auth is not None:
                 prepared_request.prepare_auth(new_auth)