Skip to content
Myr

Prevent Response self-reference in redirect history (#7328)

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

authored by Nate Prewitt · committed by GitHub · parent cbce031 · Browse files · 2 files+9 added−2 removed
This commit

State

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

Diff stats

2 files+9 added−2 removed

  • tests:+8 added−0 removed
  • other:+1 added−2 removed

2 files+9 added−2 removed

modified:src/requests/sessions.py+1 added-2 removed
177 unmodified lines
178 while url:179 prepared_request = req.copy()180181 # Update history and keep track of redirects.182 # resp.history must ignore the original request in this loop182 resp.history = hist[:]183 hist.append(resp)184 resp.history = hist[1:]184185 try:186 resp.content # Consume socket so it can be released187 except (ChunkedEncodingError, ContentDecodingError, RuntimeError):
646 unmodified lines
modified:tests/test_requests.py+8 added
215 unmodified lines
216 assert r.status_code == 200217 assert r.history[0].status_code == 302218 assert r.history[0].is_redirect219220 def test_redirect_history_no_self_reference(self, httpbin):221 r = requests.get(httpbin("redirect", "3"))222 assert r.status_code == 200223 assert len(r.history) == 3224 for i, resp in enumerate(r.history):225 assert resp not in resp.history226 assert resp.history == r.history[:i]227228 def test_HTTP_307_ALLOW_REDIRECT_POST(self, httpbin):229 r = requests.post(230 httpbin("redirect-to"),231 data="test",
2821 unmodified lines