diff options
author | Nate Prewitt <Nate.Prewitt@gmail.com> | 2018-04-07 15:11:00 -0700 |
---|---|---|
committer | Nate Prewitt <Nate.Prewitt@gmail.com> | 2018-04-07 15:11:00 -0700 |
commit | c7cea32304c05ef5890bcb8941edc8b6fbe04a03 (patch) | |
tree | 7a5d670da7f5b7a8403537f2099435ce2407194e /requests/sessions.py | |
parent | 9c6bd54b44c0b05c6907522e8d9998a87b69c1cd (diff) | |
parent | b66908e7b647689793e299edc111bf9910e93ad3 (diff) | |
download | python-requests-updating_3.0.0.tar.gz |
Merge remote-tracking branch 'upstream/master' into updating_3.0.0updating_3.0.0
Diffstat (limited to 'requests/sessions.py')
-rw-r--r-- | requests/sessions.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/requests/sessions.py b/requests/sessions.py index a3f59133..66ed53ea 100644 --- a/requests/sessions.py +++ b/requests/sessions.py @@ -8,7 +8,7 @@ This module provides a Session object to manage and persist settings across requests (cookies, auth, proxies). """ import os -import platform +import sys import time from collections import Mapping, OrderedDict from datetime import timedelta @@ -40,7 +40,7 @@ from .status_codes import codes from .models import REDIRECT_STATI # Preferred clock, based on which one is more accurate on a given system. -if platform.system() == 'Windows': +if sys.platform == 'win32': try: # Python 3.4+ preferred_clock = time.perf_counter except AttributeError: # Earlier than Python 3. @@ -134,6 +134,7 @@ class SessionRedirectMixin(object): history = [response] # keep track of history; seed it with the original response location_url = self.get_redirect_target(response) + previous_fragment = urlparse(request.url).fragment while location_url: prepared_request = request.copy() @@ -154,8 +155,12 @@ class SessionRedirectMixin(object): parsed_rurl = urlparse(response.url) location_url = '%s:%s' % (to_native_string(parsed_rurl.scheme), location_url) - # The scheme should be lower case... + # Normalize url case and attach previous fragment if needed (RFC 7231 7.1.2) parsed = urlparse(location_url) + if parsed.fragment == '' and previous_fragment: + parsed = parsed._replace(fragment=previous_fragment) + elif parsed.fragment: + previous_fragment = parsed.fragment location_url = parsed.geturl() # Facilitate relative 'location' headers, as allowed by RFC 7231. @@ -720,7 +725,7 @@ class Session(SessionRedirectMixin): """ for (prefix, adapter) in self.adapters.items(): - if url.lower().startswith(prefix): + if url.lower().startswith(prefix.lower()): return adapter # Nothing matches :-/ |