dbd2ef
diff --git a/requests/sessions.py b/requests/sessions.py
dbd2ef
index ef3f22b..a0a23ee 100644
dbd2ef
--- a/requests/sessions.py
dbd2ef
+++ b/requests/sessions.py
dbd2ef
@@ -89,6 +89,23 @@ def merge_hooks(request_hooks, session_hooks, dict_class=OrderedDict):
dbd2ef
 
dbd2ef
 
dbd2ef
 class SessionRedirectMixin(object):
dbd2ef
+
dbd2ef
+    def should_strip_auth(self, old_url, new_url):
dbd2ef
+        """Decide whether Authorization header should be removed when redirecting"""
dbd2ef
+        old_parsed = urlparse(old_url)
dbd2ef
+        new_parsed = urlparse(new_url)
dbd2ef
+        if old_parsed.hostname != new_parsed.hostname:
dbd2ef
+            return True
dbd2ef
+        # Special case: allow http -> https redirect when using the standard
dbd2ef
+        # ports. This isn't specified by RFC 7235, but is kept to avoid
dbd2ef
+        # breaking backwards compatibility with older versions of requests
dbd2ef
+        # that allowed any redirects on the same host.
dbd2ef
+        if (old_parsed.scheme == 'http' and old_parsed.port in (80, None)
dbd2ef
+                and new_parsed.scheme == 'https' and new_parsed.port in (443, None)):
dbd2ef
+            return False
dbd2ef
+        # Standard case: root URI must match
dbd2ef
+        return old_parsed.port != new_parsed.port or old_parsed.scheme != new_parsed.scheme
dbd2ef
+
dbd2ef
     def resolve_redirects(self, resp, req, stream=False, timeout=None,
dbd2ef
                           verify=True, cert=None, proxies=None):
dbd2ef
         """Receives a Response. Returns a generator of Responses."""
dbd2ef
@@ -209,14 +226,10 @@ class SessionRedirectMixin(object):
dbd2ef
         headers = prepared_request.headers
dbd2ef
         url = prepared_request.url
dbd2ef
 
dbd2ef
-        if 'Authorization' in headers:
dbd2ef
+        if 'Authorization' in headers and self.should_strip_auth(response.request.url, url):
dbd2ef
             # If we get redirected to a new host, we should strip out any
dbd2ef
             # authentication headers.
dbd2ef
-            original_parsed = urlparse(response.request.url)
dbd2ef
-            redirect_parsed = urlparse(url)
dbd2ef
-
dbd2ef
-            if (original_parsed.hostname != redirect_parsed.hostname):
dbd2ef
-                del headers['Authorization']
dbd2ef
+            del headers['Authorization']
dbd2ef
 
dbd2ef
         # .netrc might have more auth for us on our new host.
dbd2ef
         new_auth = get_netrc_auth(url) if self.trust_env else None
dbd2ef
diff --git a/test_requests.py b/test_requests.py
dbd2ef
index 15406a2..e19b436 100755
dbd2ef
--- a/test_requests.py
dbd2ef
+++ b/test_requests.py
dbd2ef
@@ -991,6 +991,27 @@ class RequestsTestCase(unittest.TestCase):
dbd2ef
 
dbd2ef
         assert h1 == h2
dbd2ef
 
dbd2ef
+    def test_should_strip_auth_host_change(self):
dbd2ef
+        s = requests.Session()
dbd2ef
+        assert s.should_strip_auth('http://example.com/foo', 'http://another.example.com/')
dbd2ef
+
dbd2ef
+    def test_should_strip_auth_http_downgrade(self):
dbd2ef
+        s = requests.Session()
dbd2ef
+        assert s.should_strip_auth('https://example.com/foo', 'http://example.com/bar')
dbd2ef
+
dbd2ef
+    def test_should_strip_auth_https_upgrade(self):
dbd2ef
+        s = requests.Session()
dbd2ef
+        assert not s.should_strip_auth('http://example.com/foo', 'https://example.com/bar')
dbd2ef
+        assert not s.should_strip_auth('http://example.com:80/foo', 'https://example.com/bar')
dbd2ef
+        assert not s.should_strip_auth('http://example.com/foo', 'https://example.com:443/bar')
dbd2ef
+        # Non-standard ports should trigger stripping
dbd2ef
+        assert s.should_strip_auth('http://example.com:8080/foo', 'https://example.com/bar')
dbd2ef
+        assert s.should_strip_auth('http://example.com/foo', 'https://example.com:8443/bar')
dbd2ef
+
dbd2ef
+    def test_should_strip_auth_port_change(self):
dbd2ef
+        s = requests.Session()
dbd2ef
+        assert s.should_strip_auth('http://example.com:1234/foo', 'https://example.com:4321/bar')
dbd2ef
+
dbd2ef
     def test_manual_redirect_with_partial_body_read(self):
dbd2ef
         s = requests.Session()
dbd2ef
         r1 = s.get(httpbin('redirect/2'), allow_redirects=False, stream=True)