Skip to content

fix: use current request instead of original in redirect chain#85

Open
label-hook[bot] wants to merge 1217 commits into
mainfrom
phoenix/issue-84
Open

fix: use current request instead of original in redirect chain#85
label-hook[bot] wants to merge 1217 commits into
mainfrom
phoenix/issue-84

Conversation

@label-hook

@label-hook label-hook Bot commented Apr 15, 2026

Copy link
Copy Markdown

Summary

Fixes an issue in Session.resolve_redirects where the method incorrectly copied the original request for each redirect iteration instead of using the current/modified request. This caused incorrect method selection when a redirect chain included method-changing redirects (like 303 See Other) followed by method-preserving redirects (like 307 Temporary Redirect).

Changes

  • Modified Session.resolve_redirects in requests/sessions.py to use the current prepared request as the base for subsequent redirects
  • Ensures proper method handling throughout redirect chains:
    • 303 See Other correctly changes POST to GET
    • Subsequent 307 Temporary Redirect preserves the GET method instead of reverting to original POST
  • Maintains backward compatibility for standard redirect scenarios

Testing

The fix was validated against the existing test suite. While the baseline test suite had pre-existing failures unrelated to this change, no new test failures were introduced by this modification. The change specifically addresses the redirect chain scenario described in the issue where:

  1. Initial POST request receives 303 See Other (converts to GET)
  2. Subsequent 307 Temporary Redirect should preserve GET method
  3. Previously would incorrectly revert to original POST method
  4. Now correctly maintains GET method through the chain

Closes #84


Closes #84

Kenneth Reitz and others added 30 commits October 24, 2013 10:28
Add clarification to MissingSchema error
Use builtin_str for all auto-set header values.
otherwise python3.4 warns
Modified the tests so that they use py.test convention
Improve the PreparedRequest docs.
loosen URL handling for non-native protocols
This reverts commit a8300c0, reversing
changes made to 2e196be.
Lukasa and others added 27 commits February 4, 2014 00:53
One last Charade reference to remove here.
Reference at the earliest opportunity that Server-Name-Indication is a
limitation of Python 2.6 and 2.7. Avoid describing it as a Requests
issue.
Made `.status_code` and `.reason` consistent with one another, adding some examples. Addresses psf#1225.
Document the `Response.reason` attribute.
…coding

Reinstate falling back to self.text for JSON responses
Document requirements for SNI support on Python2
New Response property, .is_redirect.
- Regardless of whether they are on the session or not
- Fixes psf#1920
The timeout is in seconds.
- Charade is gone, long live Chardet.
- cacert.pem is now taken wholesale from Mozilla so we need to display that
  itis licensed under the MPL2.0
Charade -> Chardet and Add cacert.pem license
Add timeout to stream with testing
Some people will assume that .raw() is present, and they shouldn't get
AttributeErrors when they make that assumption on a pickled Response.
However, @kennethreitz has asked that we not be too dependent on
urllib3. For that reason, set to None.
Pickled Responses should include a None value for the raw attribute
Fix Accept-Encoding in default headers
@label-hook label-hook Bot added the ai:review Phoenix AI: PR ready for review label Apr 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai:review Phoenix AI: PR ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[SWE-bench] psf__requests-1963