Skip to content
Myr

Avoid getting stuck in a loop

Before adoption: this commit came in with the history the project adopted, so no landing records it.

This prevents a case where we make a request to URL A, which 301s to B which would then 301 back to A. Alternatively, for less simple schemes, this will also prevent us from getting stuck in a loop, e.g., it will prevent the following from causing an endless loop: A -> B -> C -> D -> E -> F -- ^ \ | / ---<------------<----------<-

authored by Ian Cordasco · committed by Ian Cordasco · parent d28d45a · Browse files · 1 file+6 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+6 added−1 removed

  • other:+6 added−1 removed

1 file+6 added−1 removed

modified:requests/sessions.py+6 added-1 removed
533 unmodified lines
534 # Guard against that specific failure case.535 if not isinstance(request, PreparedRequest):536 raise ValueError('You can only send PreparedRequests.')537538 checked_urls = set()539 while request.url in self.redirect_cache:540 checked_urls.add(request.url)539 request.url = self.redirect_cache.get(request.url)541 new_url = self.redirect_cache.get(request.url)542 if new_url in checked_urls:543 break544 request.url = new_url545546 # Set up variables needed for resolve_redirects and dispatching of hooks547 allow_redirects = kwargs.pop('allow_redirects', True)548 stream = kwargs.get('stream')
116 unmodified lines