mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
Merge pull request #3886 from jvanasco/proposed/3.0.0
proposed 3.0 - altered internal loops of resolve_redirect
This commit is contained in:
@@ -12,6 +12,11 @@ Release History
|
||||
querying ``Response.is_redirect`` and ``Response.headers['location']``.
|
||||
Advanced users will be able to process malformed redirects more easily.
|
||||
|
||||
- Altered how ``SessionRedirectMixin.resolve_redirects`` and ``Session.send``
|
||||
process redirect history. Developers who subclass ``resolve_redirects`` will
|
||||
find a different ``.history`` attribute - the first element now contains the
|
||||
original response, and the last element now contains the active response.
|
||||
|
||||
2.13.0 (2017-01-24)
|
||||
+++++++++++++++++++
|
||||
|
||||
|
||||
+6
-15
@@ -103,19 +103,13 @@ class SessionRedirectMixin(object):
|
||||
reached.
|
||||
"""
|
||||
|
||||
redirect_count = 0
|
||||
history = [] # keep track of history
|
||||
history = [response] # keep track of history; seed it with the original response
|
||||
|
||||
url = self.get_redirect_target(response)
|
||||
|
||||
while url:
|
||||
prepared_request = request.copy()
|
||||
|
||||
# Update history and keep track of redirects.
|
||||
# response.history must ignore the original request in this loop
|
||||
history.append(response)
|
||||
response.history = history[1:]
|
||||
|
||||
try:
|
||||
response.content # Consume socket so it can be released
|
||||
except (ChunkedEncodingError, ConnectionError, ContentDecodingError, RuntimeError):
|
||||
@@ -209,6 +203,10 @@ class SessionRedirectMixin(object):
|
||||
allow_redirects=False,
|
||||
**adapter_kwargs
|
||||
)
|
||||
# copy our history tracker into the response
|
||||
response.history = history[:]
|
||||
# append the new response to the history tracker for the next iteration
|
||||
history.append(response)
|
||||
|
||||
extract_cookies_to_jar(self.cookies, prepared_request, response.raw)
|
||||
|
||||
@@ -657,17 +655,10 @@ class Session(SessionRedirectMixin):
|
||||
# Resolve redirects, if allowed.
|
||||
history = [resp for resp in gen] if allow_redirects else []
|
||||
|
||||
# Shuffle things around if there's redirection history.
|
||||
# If there is a history, replace ``r`` with the last response
|
||||
if history:
|
||||
# Insert the first (original) Response at the start.
|
||||
history.insert(0, r)
|
||||
|
||||
# Remove the final response from history, use it as our Response.
|
||||
r = history.pop()
|
||||
|
||||
# Save redirection history to final Response object.
|
||||
r.history = history
|
||||
|
||||
# Automatically download response body, if not in streaming mode.
|
||||
if not stream:
|
||||
r.content
|
||||
|
||||
Reference in New Issue
Block a user