Better layout for checking.
authorCory Benfield <lukasaoz@gmail.com>
Thu, 30 Jan 2014 15:11:24 +0000 (15:11 +0000)
committerCory Benfield <lukasaoz@gmail.com>
Thu, 30 Jan 2014 15:11:24 +0000 (15:11 +0000)
requests/sessions.py

index 22fe22f87681deb62f73cba13accbf72e05b72d9..531fd667de1a885e127489c384e08b6c9f30bfe6 100644 (file)
@@ -163,11 +163,9 @@ class SessionRedirectMixin(object):
             original_parsed = urlparse(resp.request.url)
             redirect_parsed = urlparse(url)
 
-            if original_parsed.hostname != redirect_parsed.hostname:
-                try:
-                    del headers['Authorization']
-                except KeyError:
-                    pass
+            if (original_parsed.hostname != redirect_parsed.hostname and
+                   'Authorization' in headers):
+                del headers['Authorization']
 
             # However, .netrc might have more auth for us. Let's get it if it
             # does.