Skip to content

Commit

Permalink
Merge pull request psf#2244 from sigmavirus24/bug/2231
Browse files Browse the repository at this point in the history
Avoid getting stuck in a loop
  • Loading branch information
kennethreitz committed Sep 25, 2014
2 parents e0d88c2 + ac44b48 commit de76fbe
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion requests/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,13 @@ def send(self, request, **kwargs):
if not isinstance(request, PreparedRequest):
raise ValueError('You can only send PreparedRequests.')

checked_urls = set()
while request.url in self.redirect_cache:
request.url = self.redirect_cache.get(request.url)
checked_urls.add(request.url)
new_url = self.redirect_cache.get(request.url)
if new_url in checked_urls:
break
request.url = new_url

# Set up variables needed for resolve_redirects and dispatching of hooks
allow_redirects = kwargs.pop('allow_redirects', True)
Expand Down

0 comments on commit de76fbe

Please sign in to comment.